This Bulk API 2.0 example guides you through creating a job, uploading data for the job, checking the status, and retrieving the results. This example uses a single, multipart request to create the job and upload the data.
In this example, BOUNDARY is used at the start, middle, and end of the file to mark the request body boundaries between the job’s details and its CSV data.
-
Copy this multipart, JSON-formatted content into a file named
newmultipartjob.json.note: Save all files in this example in your terminal’s current working directory.
--BOUNDARY Content-Type: application/json Content-Disposition: form-data; name="job" { "object":"Contact", "contentType":"CSV", "operation": "insert", "lineEnding" : "LF" } --BOUNDARY Content-Type: text/csv Content-Disposition: form-data; name="content"; filename="content" FirstName,LastName,MailingCity Astro,Nomical,San Francisco Hootie,McOwl,San Francisco Appy,Camper,San Francisco Earnie,Badger,San Francisco --BOUNDARY-- -
Create a job.
URI
/services/data/v68.0/jobs/ingest/Example of creating a job
curl https://MyDomainName.my.salesforce.com/services/data/v67.0/jobs/ingest/ -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "Content-Type: multipart/form-data; boundary=\"BOUNDARY\"" -H "Accept: application/json" -H "X-PrettyPrint:1" --data-binary @newmultipartjob.json -X POSTThe response includes the job
id, with a jobstateofUploadComplete. You use the jobidin the next steps.Example response body
{ "id" : "7303gEXAMPLE4X2QAN", "operation" : "insert", "object" : "Contact", "createdById" : "0055fEXAMPLEtG4AAM", "createdDate" : "2022-01-02T19:26:52.000+0000", "systemModstamp" : "2022-01-02T19:26:52.000+0000", "state" : "UploadComplete", "concurrencyMode" : "Parallel", "contentType" : "CSV", "apiVersion" : 68.0, "lineEnding" : "LF", "columnDelimiter" : "COMMA" }After you create a multipart job, the upload is completed for you automatically. You don’t need to manually set the job
statetoUploadCompletefor a multipart job. -
Check the job status and results with this URI.
URI
/services/data/v68.0/jobs/ingest/jobId/Example of checking job status and results
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/jobs/ingest/7303gEXAMPLE4X2QAN/ -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "Accept: application/json" -H "X-PrettyPrint:1" -X GETExample response body
{ "id" : "7303gEXAMPLE4X2QAN", "operation" : "insert", "object" : "Contact", "createdById" : "0055fEXAMPLEtG4AAM", "createdDate" : "2022-01-02T19:54:04.000+0000", "systemModstamp" : "2022-01-02T19:54:05.000+0000", "state" : "JobComplete", "concurrencyMode" : "Parallel", "contentType" : "CSV", "apiVersion" : 67.0, "jobType" : "V2Ingest", "lineEnding" : "LF", "columnDelimiter" : "COMMA", "numberRecordsProcessed" : 4, "numberRecordsFailed" : 0, "retries" : 0, "totalProcessingTime" : 50, "apiActiveProcessingTime" : 6, "apexProcessingTime" : 0 } -
Get successful results.
After a job is in the
JobCompleteorFailedstate, you can get details about which records were successfully processed.URI
/services/data/v68.0/jobs/ingest/jobId/successfulResults/Example of getting successful results
curl https://MyDomainName.my.salesforce.com/services/data/v68.0/jobs/ingest/7303gEXAMPLE4X2QAN/successfulResults/ -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "Content-Type: application/json" -H "Accept: text/csv" -H "X-PrettyPrint:1" -X GETExample response body
"sf__Id","sf__Created",FirstName,LastName,MailingCity "0038c00002hMS4kAAG","true","Astro","Nomical","San Francisco" "0038c00002hMS4lAAG","true","Hootie","McOwl","San Francisco" "0038c00002hMS4mAAG","true","Appy","Camper","San Francisco" "0038c00002hMS4nAAG","true","Earnie","Badger","San Francisco"To get details about records that encountered an error during processing, use a GET request with the
failedResultsresource. To make sure that you’re looking at the complete result set, look at unprocessed records by using theunprocessedRecordsresource. See Get Job Unprocessed Record Results.