0

I am trying to create bulk job using Bulk API 2.0, but my post request is redirected by salesforce to GET request. As a result, job is not created and I get /jobs/ingest GET response instead. I have no problem creating jobs when I use Workbench. And also my code easily gets job statuses and puts csv in /jobs/ID/batches. I am using node.js and node-fetch.

Here is my code:

const params = {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${token}`,
    'Content-Type': 'application/json; charset=UTF-8',
    Accept: 'application/json',
  },
  body: {
    operation: 'insert',
    object: 'Lead',
    contentType: 'CSV',
    lineEnding: 'CRLF',
  },
};
const response = await fetch(`https://mydomain--sandboxname.lightning.force.com/services/data/v43.0/jobs/ingest`, params);
const data = response.json();

This is the response:

HTTP/1.1 302 Found
Date: Tue, 02 Apr 2019 09:28:02 GMT
Strict-Transport-Security: max-age=31536001; includeSubDomains
Public-Key-Pins-Report-Only: pin-sha256="9n0izTnSRF+W4W4JTq51avSXkWhQB8duS2bxVLfzXsY="; pin-sha256="5kJvNEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w="; pin-sha256="njN4rRG+22dNXAi+yb8e3UMypgzPUPHlv4+foULwl1g="; max-age=86400; includeSubDomains; report-uri="https://a.forcesslreports.com/hpkp-report/nullm";
Expect-CT: max-age=0; report-uri="https://a.forcesslreports.com/Expect-CT-report/nullm";
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: upgrade-insecure-requests 
X-Robots-Tag: none
Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
Set-Cookie: BrowserId=0xWavqFmQlW1Cmb5_1ccvw;Path=/;Domain=.force.com;Expires=Sat, 01-Jun-2019 09:28:02 GMT;Max-Age=5184000
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: https://mydomain--sandboxname.my.salesforce.com/services/data/v44.0/jobs/ingest
Content-Length: 0

I tried different urls (with .my.salesforce, with just salesforce.com), still no luck.

  • Your domain is mydomain--sandboxname.lightning.force.com but should be mydomain--sandboxname.my.salesforce.com . Please use instance name from auth token response – pklochkov Apr 2 at 9:52
  • @pklochkov Would you like to post an answer so that this question can be closed? – David Reed Apr 2 at 11:38
  • @DavidReed done – pklochkov Apr 2 at 21:57
1

Your domain is mydomain--sandboxname.lightning.force.com but should be mydomain--sandboxname.my.salesforce.com .

Please use instance_url field from auth token response. Examples of how to perform this request you may find in REST API guide

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.