All requests in a batch are executed sequentially within a single database transaction. If any request fails, all changes are rolled back.
Execute batch requests
Submit multiple requests to be executed atomically in a single transaction.Request body
Array of internal request objects to execute. Each request object contains:
HTTP method:
POST, PATCH, PUT, or DELETEAPI endpoint URL (relative path starting with
/api/)Request body data (for POST, PATCH, PUT requests)
Custom headers for this specific request (Authorization headers are ignored - auth is inherited from the parent request)
Response
Returns an array of results for each request in the batch.Response body from the individual request
HTTP status code from the individual request
Supported operations
The Batch API supports the following record operations:Create record
Update record
Upsert record
PUT (upsert) operations automatically determine whether to create or update based on whether the record ID exists. If the ID exists, it updates; otherwise, it creates a new record.
Delete record
Use cases
Atomic operations
Ensure multiple related records are created or updated together, or none at all:Reducing round trips
Submit multiple independent operations in a single request:File uploads
When uploading files in batch requests, usemultipart/form-data:
When using multipart/form-data:
- Put regular fields in
@jsonPayloadas serialized JSON - Name file fields as
requests.N.fieldNameorrequests[N].fieldNamewhere N is the request index
Error handling
If any request in the batch fails, the entire transaction is rolled back and no changes are persisted.- Which request in the batch failed (index in the
requestsobject) - The specific error from that request in the
responsefield
Configuration
The Batch API must be enabled in your PocketBase settings. Configure these options:Enable or disable batch requests globally
Maximum number of requests allowed per batch
Maximum total body size in bytes (default: 128 MB)
Transaction timeout in seconds
Limitations and best practices
Limitations
- Supported operations only - Only record create, update, upsert, and delete operations are supported
- No nested batches - Cannot include batch requests within a batch
- Sequential execution - Requests execute sequentially, not in parallel
- Shared authentication - All requests inherit auth from the parent batch request
- Timeout constraints - Long-running batches may timeout (default: 3 seconds)
Best practices
- Keep batches small - Use batches for related operations, not bulk data imports
- Handle errors gracefully - Prepare for all-or-nothing transaction behavior
- Monitor timeout - Ensure batch operations complete within the configured timeout
- Use for consistency - Ideal for maintaining referential integrity across collections
- Consider alternatives - For large bulk operations, use individual requests or direct database access
Performance considerations
- Batch requests execute within a database transaction, which locks tables
- Each request in the batch is validated and executed sequentially
- File uploads in batches count toward the total body size limit
- Transaction timeout prevents long-running operations from blocking the database
Common errors
| Code | Description |
|---|---|
| 400 | Invalid batch request data or one of the requests failed |
| 403 | Batch requests are disabled or not allowed |
| 408 | Batch transaction timeout exceeded |
| 413 | Request body exceeds maximum size limit |
Example: Multi-step workflow
Create a complete blog post with tags and metadata atomically:Use
@request.data.requests.N.body.id to reference the ID of a record created in a previous request within the same batch.