function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

OAuth - Access Token issue using Web Server Flow

Hello all,


As per the documentation provided here (, I am trying to understand how OAuth works for salesforce authentication. 


What I have done so far: (I have client id and secret from a remote app)


1. Created a Sites VF Page which has a button that redirects to the salesforce authentication page (<your_client_id>&redirect_uri=<your_redirect_uri>)


2. This gives me a CODE on the redirecturi page, from here I call the  '' service passing all the required params, this gives me a access_token.


3. I have a Apex REST class, this is where I am not able to proceed. When I try to hit this url, I get an error response that says "This session is not valid for use with the REST API". I am also passing the "Authorization" header in the request.


I need someone to tell me what am I doing wrong? And the implementation done so far is correct or it needs to be changed?


Use this URL URLMapping is defines in your APEX class


Also use Authorisation Bearer by using session Id u got in prev step. 


https://<Salesforce  instance  name>/services/apexrest/<namespacename>/urlMapping name