Batch writes
Create, change or delete up to 500 rows in one request, all or nothing.
POST /{appUid}/autocrud/{table}/batch writes many rows of one table in one request and one
transaction. Either every row is written, or none is.
The examples on this page use the tables of a sample invoicing app (
invoices, vendors, payments). Your app has only the tables you create, so put your own table and column names in their place. About the example appThe body carries exactly one of three keys:
| Key | Holds | Answers |
|---|---|---|
create | Rows to create, each as a single create takes it | { "count", "uids" }, the new rows' uids in the order given |
update | { "uid", "values" } for each row to change | { "count", "affectedRows" } |
delete | The uids of the rows to delete | { "count", "affectedRows" } |
curl -X POST "$AUTHORIC_URL/$APP_UID/autocrud/invoices/batch" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 2c7a9e41-5d3b-4f08-a1e6-8b0d9c4f7a25" \
-d '{
"update": [
{ "uid": "0199b8e5-2f61-7a3c-8d40-91b6e7c2a5f3", "values": { "status": "approved" } },
{ "uid": "0199b8e5-4a08-7c1e-b5d2-3f9a6e1c8b47", "values": { "status": "approved" } }
]
}'What is checked
- Every row, as its single-row write. Each row passes the same permission (row conditions
included), validation, references, redaction rules and limits as a
POST,PATCHorDELETEof that one row would. A batch needs the permission of the write it carries: a batch of creates needscreateon the table, a batch of deletes needsdelete. A table that locks the operation refuses the batch. - One refused row refuses the batch. Nothing is written, and the error's
details.indexnames the row's position in the array, counting from 0. - Rows are named by uid. An update or delete names each row by its uid. A uid that names no row
you can reach is
404 ROW_NOT_FOUND, with itsdetails.index. There is no write by condition over REST; a handler can do that withupdateWhereanddeleteWhere. - Up to 500 rows. A larger batch is refused with
BATCH_TOO_LARGEanddetails.maxRows. Split it.
Live subscribers hear about the batch's changes once it commits, as they would hear about the same writes made one at a time. See Realtime.
Safe to send again
Send an Idempotency-Key with every batch. A repeat with the same key and body answers with the
first response and writes nothing, so a batch whose response was lost can be sent again. The rules
are the API's usual ones; see Idempotency.
Errors to branch on
| Code | Status | Means |
|---|---|---|
VALIDATION_ERROR | 400 | The body does not carry exactly one of create, update or delete, or a row failed validation (details.index). |
BATCH_TOO_LARGE | 400 | More than 500 rows. |
ROW_FIELD_NOT_ACCEPTED | 400 | A row carries id, uid, a scope column or a raw foreign key (details.index). |
ROW_REFERENCE_NOT_FOUND | 400 | A <name>_uid names no row. |
ROW_NOT_FOUND | 404 | An update or delete names a row that does not exist, or one you cannot reach (details.index). |
TABLE_LOCKED | 423 | The table does not allow this operation. |
IDEMPOTENCY_KEY_REUSED | 409 | The key was already used for a different body. |
The client SDK sends a batch with createMany, updateMany and deleteMany; see
Rows and realtime.