What is Idempotency?
Idempotency means you can safely retry the same request multiple times without creating duplicates. This is critical for:- Network failures and timeouts
- Uncertain transaction states
- Retry logic in distributed systems
- Preventing accidental duplicates
Two Idempotency Mechanisms
1. External ID Pattern
Useexternal_id field to ensure resources are created only once:
- First request: Creates resource, returns 201 Created
- Retry with same external_id: Returns existing resource, returns 200 OK
2. Idempotency-Key Header
For operations that don’t supportexternal_id, use the Idempotency-Key header:
- First request: Processes payment, returns 201 Created
- Retry with same key: Returns cached response, returns 200 OK
Resources Supporting external_id
Businesses
Invoices
Bills
Customers & Vendors
Operations Supporting Idempotency-Key Header
Invoice Payments
Bill Payments
Idempotency Key Format
Good Examples:Idempotency Window
Idempotency keys are stored for 24 hours. After that, the same key can be reused for a new transaction.
Response Status Codes
The response body is identical in both cases.
Best Practices
Generate Stable IDs
Check Response Status
Use for All Creates
Always provideexternal_id or Idempotency-Key when creating resources:
Handling Conflicts
If you retry with different data but sameexternal_id:
Example: Safe Invoice Creation
Next Steps
Error Handling
Handle errors during retries
Authentication
Token refresh during retries