Sub topic 7
Closing the job to start processing
This chapter assumes you can already create an ingest job and upload CSV data to it. You also need a valid access token and the job ID returned when you created the job.
Why the job must be closed
Uploading data does not start processing. Salesforce keeps an ingest job in the Open state until you tell it the upload is finished. Only then does it queue the data and begin writing records. If you skip this step, the job stays Open and no records are loaded.
You close the job by changing its state to UploadComplete.
Send the UploadComplete request
Send a PATCH request to the job's URL with a small JSON body:
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"}'A successful call returns HTTP 200 and the job's details. The important field is state. An abbreviated response looks like this:
{
"id": "750xx0000000001AAA",
"object": "Contact",
"operation": "insert",
"state": "UploadComplete",
"contentType": "CSV",
"lineEnding": "LF"
}The state value is UploadComplete, not InProgress. Salesforce moves the job forward on its own after that.
What changes after you close it
Closing a job is a one-way step. Once the state is UploadComplete, you cannot upload more data to that job. A further PUT to the batches endpoint is rejected. To load more records, create a new job.
The diagram shows where this step sits in the job's life.
You control only two of these transitions: UploadComplete and Aborted. Salesforce controls the rest.
Aborting instead of closing
If you uploaded the wrong file, abort the job instead of closing it. Use the same request with a different state:
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":"Aborted"}'Records that were already processed before an abort are not rolled back. Abort early, before you close the job, when you can.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The job stays `Open` and nothing loads | You never sent `UploadComplete` | Send the `PATCH` request |
| The `PATCH` request fails with a 400 error | The upload was empty, or the job is no longer `Open` | Upload data first, then close. Check the job's current state with a `GET` |
| Uploading fails after you closed the job | The job state is no longer `Open` | Create a new job |
| 401 response | The access token expired | Get a new token and retry |
The next chapter covers monitoring: how to poll the job and read its state and record counts.
Exercise
You uploaded a CSV to an ingest job and the upload returned success. Ten minutes later the job still shows state Open and zero records processed. What went wrong, and what request fixes it?
Show answer
The job was never closed. Send a PATCH request to /services/data/vXX.X/jobs/ingest/{jobId} with the body {"state":"UploadComplete"}. Salesforce then starts processing and moves the job to InProgress.