Batch Operations
Perform operations on multiple resources efficiently
Batch Operations
Efficiently perform operations on multiple resources with batch requests, reducing network overhead and improving performance.
Batch Create
Create multiple resources in a single request:
POST /api/v2/admin/batch/module-items
[
{
"ModuleId": 1522,
"Name": "Page 1",
"UrlSlug": "page-1",
"Enabled": true,
"ReleaseDate": "2026-07-07T00:00:00",
"ExpiryDate": "2099-12-31T00:00:00"
},
{
"ModuleId": 1522,
"Name": "Page 2",
"UrlSlug": "page-2",
"Enabled": true,
"ReleaseDate": "2026-07-07T00:00:00",
"ExpiryDate": "2099-12-31T00:00:00"
}
]
Batch Update
Update multiple resources at once:
PATCH /api/v2/admin/batch/module-items
[
{"Id": 123, "Enabled": false},
{"Id": 124, "Enabled": false},
{"Id": 125, "Enabled": false}
]
Batch Delete
Delete multiple resources in one request:
DELETE /api/v2/admin/batch/module-items
{
"ids": [123, 124, 125]
}
Response Format
Batch responses include status for each operation:
{
"results": [
{
"index": 0,
"success": true,
"id": 123,
"resource": {...}
},
{
"index": 1,
"success": false,
"error": "Validation failed",
"details": {...}
}
],
"successCount": 1,
"failureCount": 1
}
Limits
- Maximum 100 operations per batch request
- Operations execute sequentially, not in parallel
- Failed operations don't halt the batch (partial success is possible)
- Response includes all results, even for failed operations
Error Handling
Always check the success flag for each result:
const failed = response.results.filter(r => !r.success);
if (failed.length > 0) {
console.error(`${failed.length} operations failed`);
failed.forEach(f => {
console.error(`Index ${f.index}: ${f.error}`);
});
}
💡 Best Practice
Batch operations are not transactional. If atomicity is required, use individual requests within a workflow.
Code Examples
// JavaScript: Batch Create with Error Handling
const batchCreatePages = async (token, pages) => {
// Split into chunks of 100 (API limit)
const chunks = [];
for (let i = 0; i < pages.length; i += 100) {
chunks.push(pages.slice(i, i + 100));
}
const allResults = [];
for (const chunk of chunks) {
const response = await fetch(
'https://your-site.webinone.com/api/v2/admin/batch/module-items',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(chunk)
}
);
const result = await response.json();
allResults.push(...result.results);
// Log failures
const failures = result.results.filter(r => !r.success);
if (failures.length > 0) {
console.warn(`Batch had ${failures.length} failures:`);
failures.forEach(f => {
console.warn(` [${f.index}] ${f.error}`);
});
}
}
return allResults;
};
// Usage
const pages = [
{ModuleId: 1522, Name: 'Page 1', UrlSlug: 'page-1', Enabled: true, ReleaseDate: '2026-07-07T00:00:00', ExpiryDate: '2099-12-31T00:00:00'},
{ModuleId: 1522, Name: 'Page 2', UrlSlug: 'page-2', Enabled: true, ReleaseDate: '2026-07-07T00:00:00', ExpiryDate: '2099-12-31T00:00:00'},
// ... more pages
];
const results = await batchCreatePages(token, pages);
const successful = results.filter(r => r.success);
console.log(`Created ${successful.length} of ${pages.length} pages`);