Idempotency
Retry order creation safely with the Idempotency-Key header.
A network error can leave you unsure whether an order was created. Create an order therefore requires an Idempotency-Key header, so a retry returns the same order instead of creating a second one.
Idempotency-Key: 5f2b7c1e-9a4d-4e8b-b1c3-7d6e0a9f2c41Rules
- The key is 16 to 128 characters: letters, digits,
_and-. A UUID works well. - Generate one key per order attempt, store it with your order, and reuse it for every retry of that request.
- Keys belong to your merchant account and do not expire. Never reuse a key for a different order.
What a retry returns
| Situation | Response |
|---|---|
| Same key, same body, order already created | The original order, in its current status |
| Same key, same body, the first request is still running | 409 ORDER_IN_PROGRESS with Retry-After: 1. Retry after 1 second. |
Same key, different slug, amount, reference or URLs | 409 IDEMPOTENCY_CONFLICT |
| Missing or malformed key | 400 INVALID_INPUT |
A retried request returns the original order even if it has since been paid or has expired. When an order expires and the customer wants to pay again, create a new order with a new key.
When to retry
Retry with the same key on network errors, timeouts, 429, 500 and 503. Use exponential backoff, for example 1, 2, 4 and 8 seconds. Don't retry 400, 401, 409 IDEMPOTENCY_CONFLICT or 422: the same request fails again.