Repository navigation
Batch Requests
Arun Prakash edited this page Oct 25, 2026
·
1 revision
client.batch sends several writes in a single HTTP call using the WordPress batch endpoint (/wp-json/batch/v1, WordPress 5.6+). It saves round trips when you create, update or delete many items at once.
final response = await client.batch.run(
[
const BatchOperation.create('posts', body: {'title': 'A', 'status': 'draft'}),
BatchOperation.update('posts', 12, body: {'title': 'B'}),
BatchOperation.delete('posts', 13, force: true),
const BatchOperation(HttpMethod.post, '/my-plugin/v1/events', body: {'title': 'C'}), // explicit route
],
validation: BatchValidation.requireAllValidate, // all-or-nothing validation
);
final result = response.dataOrThrow();
for (final item in result.responses) {
print('${item.status}: ${item.body}'); // item.error is set on failure
}
print(result.succeeded.length);
print(result.failures.map((f) => f.error?.code));
final created = result.responses.first.decode((json) => Post.fromJson(json));An individual operation failing does not fail the call: check succeeded / failures. The call itself fails only on transport or authorization errors.
- Writes only (
POST,PUT,PATCH,DELETE). Reads cannot be batched. - Only routes that opted in accept batching. Core routes such as posts, pages and media do; a plugin route must declare
allow_batchin its route registration. A route that did not opt in answers that item with an error. - At most 25 requests per call by default.
chunkSize(default 25) splits longer lists into several calls that run one after another; results are concatenated in order. Raise it only if a plugin raised the server limit. - A path starting with
/is used as is, anything else is relative to/wp/v2/:BatchOperation(HttpMethod.post, '/my-plugin/v1/events', body: {...}). -
BatchValidation.normal(default) runs each item on its own;requireAllValidatevalidates everything first and runs nothing if any item is invalid. - Authorization is the client's default credentials, as for any write (Authorization).
Getting started
Requests and data
- Sending Requests
- Error Handling and Responses
- Fluent Queries
- Interfaces and Extensions
- Custom Post Types
- Batch Requests
- Embed and Fields
- Pagination and Finders
- Parallel Requests
- Streaming and Polling
- Pattern Directory Items
Behaviour
- Retries
- Caching
- Request De-duplication and Concurrency
- Middlewares
- Logging
- Offline Write Queue
- Events and Statistics
Other APIs
Extend and test
Reference