You need to sign in to do that
Don't have an account?

Invalid session ID when calling apex REST service
Hi! I'm trying to do a GET request to an Apex. I followed the OAuth 2.0 procedure to get an access token from Salesforce by using my username and password.
When using this token in the GET request to the Apex REST endpoint, I get a 401 error with the message '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]'.
What am I doing wrong?
I use the PHP code below. $token is the access token I got from the https://login.salesforce.com/services/oauth2/token request, and it is executed directly after receiving the token (xxxx is replaced):
When using this token in the GET request to the Apex REST endpoint, I get a 401 error with the message '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]'.
What am I doing wrong?
I use the PHP code below. $token is the access token I got from the https://login.salesforce.com/services/oauth2/token request, and it is executed directly after receiving the token (xxxx is replaced):
$curl = curl_init(); curl_setopt_array( $curl, array( CURLOPT_URL => 'https://xxxx.salesforce.com/services/apexrest/xxxx', CURLOPT_POST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => array( 'Authorization: Bearer ' . $token ) ) ); $response = curl_exec( $curl ); curl_close( $curl );
https://help.salesforce.com/articleView?id=remoteaccess_oauth_scopes.htm&type=5
Or (less likely since you say you make the request right away after authorization): is it possible that your IP address is changing and "Lock sessions to the IP address from which they originated" is enabled?
Tried using the URL as returned in the login request, but then I get a slightlight different response (notice: X-Content-Type-Options, X-XSS-Protection). Still the INVALID_SESSION_ID notice: