Skip to main content
The Batch API allows you to execute multiple API requests atomically within a single database transaction. This is useful for maintaining data consistency across related operations and reducing network round trips.
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.
Authentication: Optional (inherited by all batch requests)

Request body

array
required
Array of internal request objects to execute. Each request object contains:
string
required
HTTP method: POST, PATCH, PUT, or DELETE
string
required
API endpoint URL (relative path starting with /api/)
object
Request body data (for POST, PATCH, PUT requests)
object
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.
any
Response body from the individual request
number
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, use multipart/form-data:
When using multipart/form-data:
  • Put regular fields in @jsonPayload as serialized JSON
  • Name file fields as requests.N.fieldName or requests[N].fieldName where 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.
The error response indicates:
  • Which request in the batch failed (index in the requests object)
  • The specific error from that request in the response field

Configuration

The Batch API must be enabled in your PocketBase settings. Configure these options:
boolean
default:false
Enable or disable batch requests globally
number
default:10
Maximum number of requests allowed per batch
number
default:134217728
Maximum total body size in bytes (default: 128 MB)
number
default:3
Transaction timeout in seconds
If batch requests are disabled or the timeout is reached, the request will fail and return a 403 Forbidden or timeout error.

Limitations and best practices

Limitations

  1. Supported operations only - Only record create, update, upsert, and delete operations are supported
  2. No nested batches - Cannot include batch requests within a batch
  3. Sequential execution - Requests execute sequentially, not in parallel
  4. Shared authentication - All requests inherit auth from the parent batch request
  5. Timeout constraints - Long-running batches may timeout (default: 3 seconds)

Best practices

  1. Keep batches small - Use batches for related operations, not bulk data imports
  2. Handle errors gracefully - Prepare for all-or-nothing transaction behavior
  3. Monitor timeout - Ensure batch operations complete within the configured timeout
  4. Use for consistency - Ideal for maintaining referential integrity across collections
  5. 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

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.