• Steven Mortimer
  • 0 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
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:
"{"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();


	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");


			// 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

			// 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:

User-added image

User-added image