Skip to main content

Batch Operations

Batch operations allow you to perform multiple ShotGrid operations in a single API call. This significantly reduces network overhead and improves performance, especially when creating, updating, or deleting multiple entities.

Why Use Batch Operations?

Batch operations provide several benefits:
  1. Reduced Network Overhead: One API call instead of many.
  2. Improved Performance: Faster execution of multiple operations.
  3. Atomic Transactions: All operations succeed or fail together.
  4. Simplified Error Handling: Handle errors for multiple operations in one place.
  5. Reduced Server Load: Less strain on the ShotGrid server.

Basic Batch Operations

Batch Creation

Create multiple entities in a single API call:

Batch Updates

Update multiple entities in a single API call:

Batch Deletion

Delete multiple entities in a single API call:

Mixed Batch Operations

Perform different types of operations in a single batch:
Example usage:

Advanced Batch Patterns

Create a hierarchy of related entities in a single batch:

Batch with Validation

Validate data before performing batch operations:

Batch with Retry Logic

Implement retry logic for batch operations:

Chunking Large Batches

For very large batches, split them into smaller chunks:

Asynchronous Batch Processing

For very large operations, use asynchronous processing:

Best Practices

  1. Batch Size: Keep batch sizes reasonable (50-100 operations per batch).
  2. Validation: Validate data before performing batch operations.
  3. Error Handling: Implement proper error handling for batch operations.
  4. Chunking: Split large batches into smaller chunks.
  5. Retry Logic: Implement retry logic for transient errors.
  6. Transactions: Remember that ShotGrid batch operations are not fully transactional - some operations may succeed while others fail.
  7. Logging: Log batch operations for debugging and auditing.
  8. Testing: Test batch operations thoroughly, especially with edge cases.
  9. Monitoring: Monitor batch operation performance and adjust chunk sizes as needed.
  10. Async Processing: Use asynchronous processing for very large batches.

Complete Example

Here’s a complete example that demonstrates many batch operation patterns:

Next Steps

Now that you understand batch operations, you can: