Batch Operations
Batch operations allow processing hundreds or thousands of assets in a single call. The SDK automatically chunks large batches to stay within API limits.
Batch Createโ
- TypeScript
- Python
const result = await client.assets.batchCreate({
items: [
{ externalId: 'prod-001', vertical: 'pharmaceuticals' },
{ externalId: 'prod-002', vertical: 'pharmaceuticals' },
{ externalId: 'prod-003', vertical: 'pharmaceuticals' },
],
});
console.log(`Created: ${result.created}`);
console.log(`Failed: ${result.failed}`);
result = client.assets.batch_create([
{"external_id": "prod-001", "vertical": "pharmaceuticals"},
{"external_id": "prod-002", "vertical": "pharmaceuticals"},
{"external_id": "prod-003", "vertical": "pharmaceuticals"},
])
print(f"Created: {result['created']}")
print(f"Failed: {result['failed']}")
Batch Verifyโ
- TypeScript
- Python
const results = await client.assets.batchVerify([
'SER-abc123',
'SER-def456',
'SER-ghi789',
]);
for (const r of results.results) {
console.log(`${r.serial}: ${r.valid ? 'โ' : 'โ'}`);
}
results = client.assets.batch_verify([
"SER-abc123",
"SER-def456",
"SER-ghi789",
])
for r in results["results"]:
print(f"{r['serial']}: {'โ' if r['valid'] else 'โ'}")
Batch Revokeโ
- TypeScript
- Python
const result = await client.assets.batchRevoke(
['SER-abc123', 'SER-def456'],
'Recalled due to quality issue',
);
console.log(`Revoked: ${result.revoked}`);
result = client.assets.batch_revoke(
["SER-abc123", "SER-def456"],
reason="Recalled due to quality issue",
)
print(f"Revoked: {result['revoked']}")
Auto-Chunkingโ
For batches larger than 100 items, the SDK automatically splits them into chunks and aggregates the results:
# 500 items โ 5 API calls of 100 each, results merged
result = client.assets.batch_create(large_list, chunk_size=100)
You can customize the chunk size via the chunk_size parameter (default: 100).