BULK API invalid session id error for valid token - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Przemek ZachPrzemek 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:
 
"{"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:


User-added image


User-added image
Parth VasaniParth Vasani
Programming questions are best answered on https://developer.salesforce.com/forums and http://salesforce.stackexchange.com/ . This community is based on configurations and setup.
Przemek ZachPrzemek Zach
Thank you I will post this question there as well. 

How ever as per my sentence: 

"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 think I have some problem with account configuration/setup
Jayasankar BagepalliJayasankar Bagepalli
This Answers Community is focused on configuration and design questions. 
 
Any questions related to CODEare best submitted at the developer forums

You ETA will be Quick in those Forums
 
Please use below links 



https://developer.salesforce.com/forums/#!/feedtype=RECENT&criteria=ALLQUESTIONS
http://salesforce.stackexchange.com/


Hope this helps,

 If it does, please mark as best answer.

Kind Regards,
Jaya

 
Przemek ZachPrzemek Zach
Thanks Jaya sankar but I think my problem doesn't sit in the code. I have asked my questions on developer.salesforce.com and salesforce.stackexchange.com but no luck there (probably because it's not code issue!)

Pasting sentence from my question again....

"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 think this is a problem with account setup on Salesforce