Upsert records through the API
Create a record if it doesn’t exist, or update it if it does, in a single request, matched on a unique field.
Prerequisites
Section titled “Prerequisites”- The object has a field marked
unique: true(for example,emailon Account). Any unique field works as the match key, whatever its type: text, UUID, integer, decimal, boolean, or a lookup. - You know the value to match on. It can’t be
null. - If you call the API through a surface, the surface declares both
runtime.data.record.createandruntime.data.record.update.
1. Send the upsert request
Section titled “1. Send the upsert request”PUT /v1/data/core/Account/email
The {fieldKey} in the URL path must reference a field marked unique: true. The request body must include the match field (email in this example) and all required fields, since the record may be created:
{ "email": "info@acme.com", "name": "Acme Corp", "industry": "Technology"}2. Check the response status to see what happened
Section titled “2. Check the response status to see what happened”201 Createdif a new record was inserted (the response includes aLocationheader).200 OKif an existing record was updated.
The request can also fail:
409 UNIQUE_VIOLATION: a record you can’t change already holds the value. The answer is the same onePOSTgives for that body, and the other record is left as it was.403 SURFACE_SCOPE_EXCEEDED: the surface doesn’t declare both create and update.403 SEED_RECORD_IMMUTABLE: the value matches a seeded record that can’t be changed.422 VALIDATION_ERROR: the match field is missing from the body ornull(field codeREQUIRED), or another field fails validation.400 FIELD_NOT_UNIQUE: the field in the URL isn’t markedunique.
Sending the same PUT again, or several at once, is safe: one creates the record, and the others update it. Another PUT can still answer 409: when the record belongs to someone whose records you can’t change, or when it was deleted while your request was waiting. In that last case, send the PUT again.
Verification
Section titled “Verification”GET the record using the id from the response (or the Location header) and confirm the fields match what you sent. Run the same PUT request a second time with a changed field and confirm the response status is 200 OK (update), not 201 Created (create), and that the record’s id is unchanged.
See also
Section titled “See also”- Objects, records, and fields – what an object, record, and field are, and how a create-or-update request becomes rows in the database
- Create records through the API – the full validation rules, which apply to upserts as well
- Read, update, and delete records through the API
- Error code reference – every code this API can return, its HTTP status, and what it means
- FieldDefinition – full field type and validation reference