Newer Version Available
Step 4: Bulk Insert with a Multipart Request
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.
1--BOUNDARY 2Content-Type: application/json 3Content-Disposition: form-data; name="job" 4 5{ 6 "object":"Contact", 7 "contentType":"CSV", 8 "operation": "insert", 9 "lineEnding" : "LF" 10} 11 12--BOUNDARY 13Content-Type: text/csv 14Content-Disposition: form-data; name="content"; filename="content" 15 16FirstName,LastName,MailingCity 17Astro,Nomical,San Francisco 18Hootie,McOwl,San Francisco 19Appy,Camper,San Francisco 20Earnie,Badger,San Francisco 21--BOUNDARY-- -
Create a job.
URI
1/services/data/v61.0/jobs/ingest/Example of creating a job
1curl https://MyDomainName.my.salesforce.com/services/data/v61.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 job state of UploadComplete. You use the job id in the next steps.
Example response body
After you create a multipart job, the upload is completed for you automatically. You don’t need to manually set the job state to UploadComplete for a multipart job.1{ 2 "id" : "7303gEXAMPLE4X2QAN", 3 "operation" : "insert", 4 "object" : "Contact", 5 "createdById" : "0055fEXAMPLEtG4AAM", 6 "createdDate" : "2022-01-02T19:26:52.000+0000", 7 "systemModstamp" : "2022-01-02T19:26:52.000+0000", 8 "state" : "UploadComplete", 9 "concurrencyMode" : "Parallel", 10 "contentType" : "CSV", 11 "apiVersion" : 61.0, 12 "lineEnding" : "LF", 13 "columnDelimiter" : "COMMA" 14} -
Check the job status and results with this URI.
URI
1/services/data/v61.0/jobs/ingest/jobId/Example of checking job status and results
1curl https://MyDomainName.my.salesforce.com/services/data/v61.0/jobs/ingest/7303gEXAMPLE4X2QAN/ -H 'Authorization: Bearer 00DE0X0A0M0PeLE!AQcAQH0dMHEXAMPLEzmpkb58urFRkgeBGsxL_QJWwYMfAbUeeG7c1EXAMPLEDUkWe6H34r1AAwOR8B8fLEz6nEXAMPLE' -H "Accept: application/json" -H "X-PrettyPrint:1" -X GETExample response body
1{ 2 "id" : "7303gEXAMPLE4X2QAN", 3 "operation" : "insert", 4 "object" : "Contact", 5 "createdById" : "0055fEXAMPLEtG4AAM", 6 "createdDate" : "2022-01-02T19:54:04.000+0000", 7 "systemModstamp" : "2022-01-02T19:54:05.000+0000", 8 "state" : "JobComplete", 9 "concurrencyMode" : "Parallel", 10 "contentType" : "CSV", 11 "apiVersion" : 61.0, 12 "jobType" : "V2Ingest", 13 "lineEnding" : "LF", 14 "columnDelimiter" : "COMMA", 15 "numberRecordsProcessed" : 4, 16 "numberRecordsFailed" : 0, 17 "retries" : 0, 18 "totalProcessingTime" : 50, 19 "apiActiveProcessingTime" : 6, 20 "apexProcessingTime" : 0 21} -
Get successful results.
After a job is in the JobComplete or Failed state, you can get details about which records were successfully processed.
URI
1/services/data/v61.0/jobs/ingest/jobId/successfulResults/Example of getting successful results
1curl https://MyDomainName.my.salesforce.com/services/data/v61.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
1"sf__Id","sf__Created",FirstName,LastName,MailingCity 2"0038c00002hMS4kAAG","true","Astro","Nomical","San Francisco" 3"0038c00002hMS4lAAG","true","Hootie","McOwl","San Francisco" 4"0038c00002hMS4mAAG","true","Appy","Camper","San Francisco" 5"0038c00002hMS4nAAG","true","Earnie","Badger","San Francisco"To get details about records that encountered an error during processing, use a GET request with the failedResults resource. To make sure that you’re looking at the complete result set, look at unprocessed records by using the unprocessedRecords resource. See Get Job Unprocessed Record Results.