Sub topic 5
Creating an ingest job
An ingest job is the container for one bulk load. It holds the target object, the operation, and the format of the data you will upload next. This chapter covers the request that creates the job, the options it accepts, and what the response tells you.
This chapter assumes you have an OAuth access token and your org's instance URL, and that you know HTTP methods and JSON. It also assumes you know the previous chapter's job states and have a CSV prepared. Later chapters cover uploading the data and closing the job.
What creating a job does
Creating a job does not load any records. It registers your intent with Salesforce: "I will send CSV data for this object, and I want this operation applied to every row." Salesforce returns a job ID and puts the job in the Open state, where it waits for data.
Separating job creation from upload has two consequences:
- Salesforce validates the job settings (object, operation, format) before you send gigabytes of data.
- The settings apply to the whole job. You cannot mix an insert and an update in one job, and you cannot change the object after creation.
The request
Send a POST to the jobs/ingest resource with a JSON body. Replace v62.0 with a current API version.
curl -X POST "$INSTANCE_URL/services/data/v62.0/jobs/ingest" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"object":"Contact","operation":"insert","contentType":"CSV","lineEnding":"LF"}'The Content-Type header describes this request body, which is JSON. The CSV format is declared inside the body with contentType. Mixing these up is a common mistake. The CSV upload later uses its own text/csv header.
Request fields
| Field | Required | Meaning |
|---|---|---|
| `object` | Yes | API name of the target object, such as `Contact` or `Invoice__c`. |
| `operation` | Yes | `insert`, `update`, `upsert`, `delete`, or `hardDelete`. |
| `contentType` | No | The data format. For ingest, the value is `CSV`, which is also the default. |
| `lineEnding` | No | `LF` (default) or `CRLF`. Must match your file. |
| `columnDelimiter` | No | `COMMA` (default), `TAB`, `PIPE`, `SEMICOLON`, `CARET`, or `BACKQUOTE`. |
| `externalIdFieldName` | Upsert only | The external ID field used to match existing records. |
| `assignmentRuleId` | No | An assignment rule to apply, for objects such as Case and Lead. |
I recommend setting contentType and lineEnding explicitly even where defaults exist. A script that states its format is easier to review, and it does not depend on a default that your file might not match.
Choosing the operation
The operation determines what each CSV row means and which columns it needs.
| Operation | What each row does | Required columns |
|---|---|---|
| `insert` | Creates a new record. | Required fields for the object. |
| `update` | Changes an existing record. | `Id`, plus the fields to change. |
| `upsert` | Updates a match, otherwise inserts. | The external ID column, plus fields. |
| `delete` | Moves a record to the Recycle Bin. | `Id` |
| `hardDelete` | Deletes a record permanently, skipping the Recycle Bin. | `Id` |
For upsert, you must also pass externalIdFieldName. A later chapter covers it in detail. This is what the body looks like:
{
"object": "Contact",
"operation": "upsert",
"externalIdFieldName": "Legacy_Id__c",
"contentType": "CSV",
"lineEnding": "LF"
}hardDelete needs an extra permission, "Bulk API Hard Delete", on the user's profile or permission set. Because the deletion cannot be undone, treat it with more caution than any other operation here.
Matching lineEnding to your file
lineEnding tells Salesforce which character sequence ends each CSV row. If it does not match the file, Salesforce misreads the rows. Files saved on Windows often use CRLF. Files from Linux, macOS, and most scripts use LF.
Check a file before you load it:
file contacts.csvThe output includes "with CRLF line terminators" for Windows-style files. If it says nothing about line terminators, the file uses LF. If you are unsure, convert the file to LF and keep the job setting at its default.
The same rule applies to columnDelimiter. If a field value can contain your delimiter, the CSV rules still apply: wrap the value in double quotes. Choosing PIPE or TAB is useful when your text fields contain many commas.
Reading the response
A successful call returns 200 OK and a JSON description of the new job:
{
"id": "7505g00000ABCdeAAH",
"operation": "insert",
"object": "Contact",
"createdById": "0055g00000XYZabAAA",
"createdDate": "2026-12-01T09:00:57.000+0000",
"systemModstamp": "2026-12-01T09:00:57.000+0000",
"state": "Open",
"concurrencyMode": "Parallel",
"contentType": "CSV",
"apiVersion": 62.0,
"jobType": "V2Ingest",
"contentUrl": "services/data/v62.0/jobs/ingest/7505g00000ABCdeAAH/batches",
"lineEnding": "LF",
"columnDelimiter": "COMMA"
}Keep three values:
ididentifies the job in every later call: upload, close, monitor, and results.stateshould beOpen. Any other state at this point means something is wrong.contentUrlis the relative path where you upload data. It is thebatchesresource under the job.
jobType is V2Ingest, which separates these jobs from the older Bulk API jobs. concurrencyMode is Parallel. You do not set it. Salesforce processes the data in parallel, which is why the performance chapter discusses lock contention.
Creating a job from Python
This script creates the job and stops at the response, so you can inspect it. It reads credentials from environment variables, as the end-to-end script will.
import os
import requests
instance = os.environ["SF_INSTANCE_URL"]
token = os.environ["SF_ACCESS_TOKEN"]
url = f"{instance}/services/data/v62.0/jobs/ingest"
body = {
"object": "Contact",
"operation": "insert",
"contentType": "CSV",
"lineEnding": "LF",
}
resp = requests.post(
url,
headers={"Authorization": f"Bearer {token}"},
json=body,
timeout=30,
)
if resp.status_code != 200:
print("Job creation failed:", resp.status_code, resp.text)
resp.raise_for_status()
job = resp.json()
print("Job ID:", job["id"])
print("State:", job["state"])
print("Upload to:", job["contentUrl"])The json= argument sets Content-Type: application/json for you. The script prints the response body on failure, because Salesforce error messages name the problem and raise_for_status() alone hides them.
Common errors
Errors at this step come back as a JSON array with an errorCode and a message.
| Symptom | Likely cause | Fix |
|---|---|---|
| `401` with `INVALID_SESSION_ID` | The token is expired or belongs to another org. | Get a new token and check `INSTANCE_URL`. |
| `403` or an API-access error | The user lacks the "API Enabled" permission. | Grant it through a profile or permission set. |
| `400` naming the object | The object API name is wrong or not visible to the user. | Check spelling, the `__c` suffix, and object permissions. |
| `400` about the operation | A misspelled value, such as `Insert` or `upsertt`. | Use one of the five values exactly as written. |
| `400` for an upsert | `externalIdFieldName` is missing or is not an external ID field. | Mark the field as External ID and name it exactly. |
| `404` | The URL path or API version is wrong. | Confirm `/services/data/vNN.N/jobs/ingest`. |
Checking your work
Before you move on, verify the job exists by fetching it with a GET to jobs/ingest/$JOB_ID. The response matches the one above, and state should still read Open. The same call becomes your monitoring call once the job is closed.
Exercise
You need to apply a nightly file from a Windows system to the Contact object. Rows for existing contacts must be updated, and rows for new contacts must be created. The file uses a custom field Legacy_Id__c as the key and has CRLF line endings. Write the JSON body for the job, and name the one field that is easy to forget.
Show answer
{"object":"Contact","operation":"upsert","externalIdFieldName":"LegacyIdc","contentType":"CSV","lineEnding":"CRLF"}. The easy-to-forget field is externalIdFieldName, which is required for upsert, and LegacyId__c must be marked as an External ID field on Contact. Setting lineEnding to CRLF matches the Windows file.
Exercise
A job-creation call returns 200 with "state": "Open". You have not uploaded any data yet. Are any records loaded at this point, and what do you use from the response to continue?
Show answer
No records are loaded. Creating a job only registers the settings. You continue with the id for all later calls and the contentUrl as the place to upload the CSV data.