Salesforce Bulk Job CSV Upload via Google Apps Script UrlFetchApp

梦想的初衷 提交于 2020-01-25 00:25:10

问题


I'm attempting to use Google Apps Script to access Salesforce's Bulk API 2.0 and upload the CSV data to a job, however Salesfore is returning

[{"errorCode":"METHOD_NOT_ALLOWED","message":"HTTP Method 'GET' not allowed. Allowed are PUT"}]

Given my experience with the Salesforce API, I highly doubt the issue is actually with the method type, but that there is some other validation which is causing this error. However, upon inspection of the request body and comparing it to what I successfully submit through cURL, I don't see what I can do to resolve.

The request code:

var headers = {
  "Authorization": "Bearer TOKEN"
};
var options = {
  "method": "put",
  "contentType": "text/csv",
  "headers": headers,
  "payload": "Id,Entity_Name__c\n001,One\n002,Two\n003,Three"
};
var url = INSTANCE + "/services/data/v44.0/jobs/ingest/" + JOB_ID + "/batches";
UrlFetchApp.fetch(url, options);

Google Apps Script request as returned via getRequest():

{
  "headers": {
    "Authorization": "Bearer TOKEN"
  },
  "method": "put",
  "payload": "Id,Entity_Name__c\n001,One\n002,Two\n003,Three",
  "followRedirects": true,
  "validateHttpsCertificates": true,
  "useIntranet": false,
  "contentType": "text/csv",
  "url": "INSTANCE/services/data/v44.0/jobs/ingest/JOB_ID/batches"
}

cURL request:

curl --request PUT \
  --url INSTANCE/services/data/v44.0/jobs/ingest/JOB_ID/batches \
  --header 'authorization: Bearer TOKEN' \
  --header 'content-type: text/csv' \
  --data '"Id,Entity_Name__c\n001,One\n002,Two\n003,Three"'

How can I resolve this?

来源:https://stackoverflow.com/questions/55758941/salesforce-bulk-job-csv-upload-via-google-apps-script-urlfetchapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!