Sub topic 2
Uploading the Data
Assume you have an OAuth access token, a Bulk API 2.0 ingest job in the Open state, and its ID in JOB_ID. The CSV header must use Salesforce field API names.
Upload the CSV
Send the file with PUT to the job's batches endpoint. Use --data-binary so the CSV bytes and line endings are preserved.
curl -X PUT "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID/batches" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: text/csv" \
--data-binary @contacts.csvThe upload response does not mean that records have been processed. It only places data in the job.
Close the Job
Set the job state to UploadComplete. This tells Salesforce that no more data will be uploaded and starts processing.
curl -X PATCH "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"state":"UploadComplete"}'After this change, do not upload another file to the same job. Create a new job if the source data needs correction.
Monitor Progress
Poll the job endpoint until it reaches a terminal state.
curl "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID" \
-H "Authorization: Bearer $ACCESS_TOKEN"Inspect state, numberRecordsProcessed, and numberRecordsFailed. JobComplete means processing ended, not that every row succeeded. Failed or Aborted means the job did not finish normally.
Read the Results
After completion, retrieve each result set:
curl "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID/successfulResults/" \
-H "Authorization: Bearer $ACCESS_TOKEN"
curl "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID/failedResults/" \
-H "Authorization: Bearer $ACCESS_TOKEN"
curl "$INSTANCE_URL/services/data/v62.0/jobs/ingest/$JOB_ID/unprocessedrecords/" \
-H "Authorization: Bearer $ACCESS_TOKEN"Successful results include created or updated record IDs. Failed results include the input fields and an sf__Error column. Unprocessed records were not attempted, often because the job stopped early. Correct failed or unprocessed rows, then submit them in a new job.
Exercise
Which action starts Salesforce processing after a CSV upload?
Show answer
PATCH the job with {"state":"UploadComplete"}.