curl - Salesforce REST API with PHP, INVALID_SESSION_ID after successful authentication -
i connected web app salesforce , followed steps in web server oauth flow access_token , related info: https://developer.salesforce.com/docs/atlas.en-us.api_placeorder.meta/api_placeorder/intro_understanding_web_server_oauth_flow.htm
every step seems return expected set of results specified in docs, when try make requests final access token, error saying session id invalid. here code:
// execute request access_token , related info $output = json_decode(curl_exec($ch)); curl_close($ch); var_dump($output); // extract token , instance_url output $sf_url = $output->instance_url . '/services/data/v35.0/'; $sf_auth = 'bearer ' . $output->access_token; // execute new curl request auth values $ci = curl_init(); curl_setopt($ci, curlopt_url, $sf_url); curl_setopt($ci, curlopt_returntransfer, true); curl_setopt($ci, curlopt_httpheader, array( 'accept' => '*/*', 'authorization' => $sf_auth, 'x-prettyprint' => 1 )); $output2 = curl_exec($ci); curl_close($ci); var_dump($output2);
the dump $output gives:
object(stdclass)#194 (7) { ["access_token"]=> string(112) "xxxxxxxxxxxxxxxx" ["signature"]=> string(44) "xxxxxxxxxxxxxx" ["scope"]=> string(3) "api" ["instance_url"]=> string(27) "https://cs10.salesforce.com" ["id"]=> string(68) "https://test.salesforce.com/id/xxxxx/xxxxx" ["token_type"]=> string(6) "bearer" ["issued_at"]=> string(13) "1453358xxxxxx" }
the dump $output2 gives:
string(75) "[{"message":"session expired or invalid","errorcode":"invalid_session_id"}]"
any here appreciated.
* update *
i tried using username-password auth flow, , i'm getting same result. can access token, can't query database, , error being returned same invalid_session_id.
i used postman plugin chrome, passed in same info username-password flow, , works making queries. i'm not sure being done differently, seems data being passed same.
i found answer, had wrong syntax setting curl headers. tried pass values associative array, correct way this:
curl_setopt($ci, curlopt_httpheader, array( 'accept: application/json', 'authorization:' . $sf_auth, 'x-prettyprint:1' ));
Comments
Post a Comment