Batch Requests
The public query API can run the same query many times in a single request. Instead of sending one call per row, you send one call containing an array of payloads — ideal for bulk inserts and updates.
How it works
Send a POST, PUT, PATCH or DELETE request whose JSON body is itself an
array of objects. Kvery loops over the array and runs the query once for each
object, passing that object's keys to the query as parameters:
curl -X POST "https://app.kvery.io/query/api/{hash}" \
-H "Content-Type: application/json" \
-d '[
{ "name": "Ada", "email": "[email protected]" },
{ "name": "Alan", "email": "[email protected]" },
{ "name": "Grace","email": "[email protected]" }
]'
The query (for example INSERT INTO users (name, email) VALUES ('$name', '$email'))
runs three times — once per object in the array. Each object's keys map to the
matching $-prefixed form variables in the
SQL.
A body that is a single JSON object counts as one row: the query runs once with its
values. A request with an empty body (or {} / []) runs the query once, without
row values.
Stops on the first failure
The loop processes items in order and stops as soon as one iteration returns
a non-200 status. Items before the failure have already executed; items after
it do not run. Design your query so partial progress is acceptable, or guard each
item so a bad row fails cleanly.
Each row counts as one call for the query's
rate limit. When the limit is
reached in the middle of a batch, that row is answered with 429 and "Rate limit
exceeded. Try again later." (with a Retry-After header), and the rows after it do
not run.
The response
The call answers with the output of the last row that ran: the last row's
answer when every row succeeded, otherwise the answer of the row that stopped the
batch. The outputs of the earlier rows are not returned, and a return() /
returnk() helper only
answers on the last row of the batch. When that row produces no output, the call
answers with status 500.
Iteration variables
Within each iteration Kvery exposes two values you can reference in SQL:
| Variable | Meaning |
|---|---|
$_rawIndex | the current item's position in the batch (1-based) |
$_rawLastIndex | the total number of items in the batch |
These let a query know where it is in the batch — useful for ordering, logging, or behaving differently on the last item.
Tips
- Keep batches reasonably sized; very large arrays mean a long-running request.
- Because the loop halts on the first error, return a clear status with
SET HTTPCODEso the caller knows which item failed. - For a single operation, send one JSON object (or form fields) — see the public query API.