3

Following the Salesforce Bulk API v2.0 documentation at:

https://developer.salesforce.com/docs/atlas.en-us.api_bulk_v2.meta/api_bulk_v2/walkthrough_upload_data.htm

https://developer.salesforce.com/docs/atlas.en-us.api_bulk_v2.meta/api_bulk_v2/create_job.htm

yields an INVALID_SESSION_ID response when attempting to create a job; after receiving an access token:

$ curl "https://<instance>.salesforce.com/services/oauth2/token?grant_type=password&client_id=<client_id>&client_secret=<client_secret>&username=<username>&password=<password+token>" -X POST -H "Accept: application/json"

when creating a job, an invalid session Id response is always returned:

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

even though the instance and access token have an eight hour availability.

Job creation is done by calling:

$ curl  'https://<instance>.salesforce.com/services/data/v43.0/jobs/ingest' -H 'content_type: json' -H 'accept: json' -H 'Authorization: Bearer <previously_returned_OAuth_access_token>' -d '{"object":"Contact","operation":"insert”}'

Bulk v2.0 is available since v41.0. The Contact table is present on salesforce. The error persists even when a different object is used:

$ curl  'https://<instance>.salesforce.com/services/data/v43.0/jobs/ingest' -H 'content_type: json' -H 'accept: json' -H 'Authorization: OAuth previously_returned_OAuth_access_token' -d @jobV2.txt

where jobV2.txt contains:

{
  "externalIdFieldName": "",
  "lineEnding": "CRLF",
  "operation": "upsert",
  "object": "Account",
  "contentType": "csv"
}

Why is there always an INVALID_SESSION_ID message being received?

Edit:

Running a query works as expected:

$ curl 'https://<instance>.salesforce.com/services/data/v43.0/query/?q=SELECT+name+from+Account' -H 'Authorization: Bearer <session_id>'
{"totalSize":21,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v43.0/sobjects/Account/0010X00004EUJheQAH"},"Name":"Name #1"},{"attributes":{"type":"Account","url":"/services/data/v43.0/sobjects/Account/0010X00004EUJhfQAH"},"Name":"Name #2"},{"attributes":{"type":"Account","url":"/services/data/v43.0/sobjects/Account/0010X00004EUJhgQAH"},"Name":"Name #3"},{"attributes":{"type":"Account","url":"/services/data/v43.0/sobjects/Account/0010X00004C1r8TQAR"},"Name":"Name #4"},{"attributes":{"type":"Account","url":"/services/data/v43.0/sobjects/Account/0010X00004DhSb1QAF"},"Name":"Name #5"}]}
  • 2
    As a test, have you verified if your token is valid for any other REST API calls? – Jayant Das Oct 29 '18 at 12:59
  • Yes, it does. I tried running a query (edited the answer) – Sebi Oct 29 '18 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.