You need to sign in to do that
Don't have an account?
Przemek Zach
BULK API invalid session id error for valid token
Hi I am building Salesforce app which authenticate users using oAuth2. When user complete authentication I am receiving access_token. When I use this token with REST API it works perfectly fine. When I try to use it with BULK API I get this error:
The token must be valid because it works with REST API calls.
The user I am authenticating has "System administrator" profile selected and user license is "Salesforce". User has "Development Edition" so the API is enabled by default.
This is the code for creating BULK API job:
This is the error message I get:
The code is in PHP and it works perfectly fine when providing token for different salesforce developer account so I am assuming this is a problem with account setup on Salesforce.
I am attaching screenshots of my oauth app settings:
"{"exceptionCode":"InvalidSessionId","exceptionMessage":"Invalid session id"}"
The token must be valid because it works with REST API calls.
The user I am authenticating has "System administrator" profile selected and user license is "Salesforce". User has "Development Edition" so the API is enabled by default.
This is the code for creating BULK API job:
$job = createJob(); var_dump($job); function createJob() { $accessToken = "mytokengoeshere"; try { // Initializate Guzzle client $client = new Client(); // Request URI $request = $client->post("https://eu6.salesforce.com/services/async/37.0/job"); ## SET HEADERS // Add authentication token to the header $request->addHeader('X-SFDC-Session', $accessToken); // Set content type to JSON $request->addHeader('content-type', 'application/json'); // Query data $data = json_encode( array("operation" => "query", "object" => "Account", "concurrencyMode" => "Parallel", "contentType" => "JSON") ); // Set body for Guzzle request $request->setBody($data); // Send the request and get the response $response = $request->send(); // Convert response to JSON format $jsonResponse = $response->json(); return $jsonResponse; } catch (ClientErrorResponseException $exception) { // Return exception message return $exception->getResponse()->getBody(true); } }
This is the error message I get:
"{"exceptionCode":"InvalidSessionId","exceptionMessage":"Invalid session id"}"
The code is in PHP and it works perfectly fine when providing token for different salesforce developer account so I am assuming this is a problem with account setup on Salesforce.
I am attaching screenshots of my oauth app settings:
Can you confirm that the session is valid on the eu6 pod?
What if you borrow the session id from the sid cookie in the browser for an admins web session?
I did borrow session id from the sid cookie, and tried it with both REST API and BULK API.
It worked with REST API but not with BULK API...
Has anyone reached a solution concerning the Invalid session id error? The session is set correctly, but the error keeps showing up! :(
- call https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<my_client_id>&redirect_uri=<my_redirect_uri> to fetch a valid code parameter.
- use this code param to fetch correct access_token by call
login.salesforce.com/services/oauth2/token?grant_type=authorization_code&redirect_uri=<my_redirect_uri>&client_id=<my_client_id>&client_secret=<my_client_secret>&code=<code_just_fetched>by using those two steps, we can fetch valid access_token.