What is Idempotency?
Idempotency ensures that making the same API request multiple times produces the same result as making it once. This is critical for:- Network failures: Retry safely without creating duplicates
- Timeouts: Resubmit requests that timed out
- Distributed systems: Handle concurrent requests
How It Works
Include anidempotencyKey in your POST requests:
- The system recognizes the duplicate
- Returns the original response without re-executing
- No duplicate resources are created
Implementation
Generate Unique Keys
Use a consistent strategy for generating keys:Example: Safe Order Creation
Idempotency Rules
Key Requirements
Key Requirements
- Length: 8-64 characters
- Characters: Alphanumeric, hyphens, underscores
- Uniqueness: Must be unique per operation type
- Expiry: Keys expire after 24 hours
Scope
Scope
- Keys are scoped to your API key (not global)
- Same key can be used for different endpoints
- Example:
order-123for/orders/createis different fromorder-123for/orders/void
Response Behavior
Response Behavior
- First request: Operation executes, response cached
- Duplicate request: Cached response returned (HTTP 200)
- Different payload, same key: Error returned (409 Conflict)
Endpoints Supporting Idempotency
| Endpoint | idempotencyKey |
|---|---|
POST /api/v1/orders/create | Required |
POST /api/v1/manifests/submit | Optional |
POST /api/v1/orders/void | Required |
POST /api/v1/labels/{id}/reprint | Required |
Common Patterns
Pattern 1: Order ID as Key
Best for e-commerce integrations:✅ Natural deduplication if order already processed
✅ Easy to debug
Pattern 2: Request Hash
Best for operations without natural IDs:⚠️ Different results for slightly different payloads
Pattern 3: Timestamp + ID
Best for retry-heavy workflows:⚠️ Doesn’t prevent accidental duplicates
Handling Conflicts
If you send a different payload with the same key:Best Practices
Do
- Use predictable keys (order IDs)
- Store keys with requests for debugging
- Retry with same key on failures
Don't
- Generate random keys per retry
- Reuse keys for different operations
- Rely on idempotency for business logic