Skip to main content

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

On a write request (POST / PUT / PATCH / DELETE), include a _rawBody field whose value is an array of objects. Kvery loops over the array and runs the query once for each object, merging that object's keys into the request as parameters:

curl -X POST "https://app.kvery.io/query/api/{hash}" \
-H "Content-Type: application/json" \
-d '{
"_rawBody": [
{ "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.

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.

Iteration variables

Within each iteration Kvery exposes two values you can reference in SQL:

VariableMeaning
_rawIndexthe current item's position in the batch (1-based)
_rawLastIndexthe 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 HTTPCODE so the caller knows which item failed.
  • For a single operation, omit _rawBody and pass parameters normally — see the public query API.