• Roelofs
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
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):
$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 );
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):
$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 );
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):
$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 );