Skip to content

Writing many records at once

POST /records/graph applies an ordered list of record operations in one transaction. Every operation is applied, or none is. Use it whenever one thing you save is several records: an invoice and its lines, an order and its items, a job and its tasks.

A refused operation leaves nothing behind: no record, no metadata row and no attached file. The answer is one error that names the operation.


POST https://api.tessule.com/api/records/graph
Authorization: Bearer crm_...
Idempotency-Key: scan-INV-1042
Content-Type: application/json
{
"operations": [
{ "op": "create", "ref": "inv", "table": "invoices",
"data": { "invoice_number": "INV-1042", "total": 1260 },
"metadata": { "detections": { "total": { "page": 1, "confidence": 62, "read_text": "1,260.00" } } } },
{ "op": "create", "table": "invoice_lines",
"data": { "invoice": { "ref": "inv" }, "description": "Boiler service", "amount": 960 } },
{ "op": "update", "table": "suppliers", "id": "rec_0123abcd",
"expectedUpdatedAt": "2026-11-12T09:00:00.000Z", "data": { "last_invoice": { "ref": "inv" } } }
]
}

Each operation names its table by id or by name, and takes the same data as the single-record write:

op Takes Does
create table, data, optional ref and metadata Creates a record. Staged attachment keys bind as they do on a single create.
update table, id, data, optional expectedUpdatedAt and metadata Changes the fields named in data; the rest are left alone.
delete table, id, optional expectedUpdatedAt Moves the record to the recycle bin, with the records a cascade reference takes along.

dryRun: true runs every check and keeps nothing.

The per-workspace OpenAPI spec types this request to your workspace: each operation’s table is one of your tables and its data that table’s fields, so a client generated from it refuses an unknown table, an unknown field or a missing required value before the request is sent.

A request holds at most 500 operations, counting each metadata row as one.

Refs: pointing at a record the request creates

Section titled “Refs: pointing at a record the request creates”

A create may declare a ref: lowercase letters, digits and underscores, unique in the request. A later operation points at that record with { "ref": "<name>" } wherever a record id goes: a reference field’s value, the recordId of a polymorphicReference value, or one entry of a multiReference list.

A ref points backwards only, at a create earlier in the list. An update or delete takes the id of a record that already exists.

Every operation is checked like a single write

Section titled “Every operation is checked like a single write”

Permissions, row access, field restrictions, value rules, references, constraints and stage rules apply to each operation exactly as they do one record at a time. Each operation checks its own action: records:create, records:update or records:delete. A caller who holds none of the three is refused before anything is checked.

metadata writes the record’s metadata rows through the same checks as the single metadata write, including the caller’s grant on each metadata table.

An update that an approval rule would intercept refuses the whole request with APPROVAL_REQUIRED. Request approval for that record on its own.

With expectedUpdatedAt, an update or delete is refused with STALE_RECORD when another write has moved the record, including a write made while the request was being checked.

Events, history, webhooks and flows see one event per record, as they do for single writes. Each event’s metadata carries graph: { requestId, index }.

On success, 200 with one result per operation, in request order:

{
"results": [
{ "index": 0, "op": "create", "ref": "inv", "table": "rec_0123abcd", "id": "rec_0123abcd", "updatedAt": "2026-11-12T09:00:01.000Z" },
{ "index": 1, "op": "create", "table": "rec_0123abcd", "id": "rec_0123abcd", "updatedAt": "2026-11-12T09:00:01.000Z" },
{ "index": 2, "op": "update", "table": "rec_0123abcd", "id": "rec_0123abcd", "updatedAt": "2026-11-12T09:00:01.000Z", "changed": true }
],
"replayed": false
}

On a refusal, nothing is written. The error keeps the status and code the single-record write gives, and operation names the first operation that failed:

{
"error": "Validation failed",
"code": "VALIDATION_ERROR",
"details": { "amount": "Field 'Amount': must be number" },
"operation": { "index": 1, "table": "invoice_lines", "field": "amount" }
}

A metadata row is named <metadata table>.<field>, such as detections.total.

Status, code Meaning
400 GRAPH_REF_INVALID A ref is unknown, declared twice, or points forwards.
400 VALIDATION_ERROR, UNIQUE_VIOLATION A value, reference or constraint refused, with details (and conflict for a unique clash).
400 GRAPH_TOO_LARGE More than 500 operations, counting metadata rows.
403 PERMISSION_DENIED, or a metadata code The caller lacks an action, a field or a metadata grant.
404 A table or record the caller cannot see.
409 STALE_RECORD, APPROVAL_REQUIRED, IDEMPOTENCY_KEY_IN_FLIGHT, TRANSACTION_CONFLICT Another write moved a record; an approval rule would intercept an update; the key’s first request is still running; another write held records this one needed, so send it again.
422 IDEMPOTENCY_KEY_REUSED The key was used for a different request in the last 24 hours.

Send an Idempotency-Key header (1 to 255 characters) with every request you may retry. A retry with the same key and the same body answers the first request’s result with "replayed": true and writes nothing, for 24 hours after the first request. A key is yours alone: another caller’s request with the same key is unaffected.

A refused request stores nothing, so its retry runs afresh. A dry run neither reads nor stores the key.

Over MCP, the write_records tool takes the same operations, with expected_updated_at for expectedUpdatedAt, and is listed with the other record write tools. See AI assistants.

Open the app