I have used the salesforce REST API a ton in the past, but I am at the point where I need more speed for fetching/inserting/updating a large number of records at once. I have a remote application using the rest api that has been working great and am trying to extend it to also be able to use the bulk api. The problem is I get an "InvalidSessionId" error when trying to query the Bulk API, but not when I query the REST API. The closest I found to an answer was: https://success.salesforce.com/answers?id=9063A000000iUovQAE but the people there did not help the poster. I've looked through the salesforce docs, but in my opinion they are not very helpful. The only mention of session id (that I could find) is by using a SOAP call to login, but they also say the Bulk API is based on REST principles which doesn't make a lot of sense.

My query to the REST API: HTTP_METHOD: get URL: https://myinstance.salesforce.com/services/data/v37.0/sobjects/Account/0000000000 HTTP_HEADERS: { Authorization: 'Bearer MyAccessTokenString' }

Query to the Bulk API:

HTTP_METHOD: post URL: https://mysfinstance.salesforce.com/services/async/v37.0/job HTTP_BODY: {"operation":"query","object":"Account","contentType":"CSV"} HTTP_HEADERS: { Authorization: 'Bearer MyAccessTokenString', 'Content-Type': 'application/json' }

The REST API query gives me back the account as expected. The Bulk API query returns InvalidSessionId. What am I missing here?


1 Answer 1


The Bulk api predates OAuth2(!) and so doesn't use the Authorization: Bearer header approach for auth, you need instead to send a X-SFDC-Session: header. see the docs

  • Alright, that is odd but I guess it is what it is.
    – buphmin
    Commented Aug 4, 2018 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .