1

I have rest resource class which i am calling from force.com site..

Below is my site url

http://partial-sms.cs31.force.com/webhook

@RestResource(urlMapping='/webhook/*')

global  without sharing class smsSiteAPI {
   @HttpGet
    global static ID getUrlParameters(){

        Id urlId = apexpages.currentpage().getparameters().get('id');

        system.debug('Url id '+urlId);

        return urlID;
    }

}

And below is the Active Site Home Page

<apex:page controller="smsSiteAPI">
    <apex:outputText value="{!UrlParameters}" />
</apex:page>

when i hit url "https://partial-sms.cs31.force.com/webhook?id=1234" it gives error: "Authorization Required You must first log in or register before accessing this page. If you have forgotten your password, click Forgot Password to reset it."

I already have permission to the class smsSiteAPI

  • Have you granted access to the class to the site guest user? – Girbot Sep 10 '19 at 13:41
  • Yes i granted access to the class to the site guest user. – jsmith Sep 10 '19 at 13:44
0

You need to grant the APEX class access to the site profile. Please find below format for calling the API from the site.

https://<site-url>/services/apexrest/<your-web-service-name>

If the class is part of the managed package, then you need to include the package namespace as well.

https://<site-url>/services/apexrest/<namespace>/<your-web-service-name>

With the above-mentioned format it working, see!

enter image description here

| improve this answer | |
  • Thanks Rahul! but why it is showing is under construction? Why not i am able to see output at developer console? Please help me, I am new to such scenario. – jsmith Sep 10 '19 at 16:37
  • 1
    @jsmith - you need to set debug log traces for the site guest user to see debug output; not for you, the developer – cropredy Sep 10 '19 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.