- Where
- Your own system
- Who can do it
- Developers
- Plans
- REST API is included in Growth, Scale and Enterprise
In detail
Networks fail at the worst moment: your booking request reaches the server, the delivery is booked, and the answer is lost on the way back. Without protection, a retry books a second delivery. An idempotency key makes the retry safe.
How it works
- Send
Idempotency-KeywithPOST /api/v1/shipments. Any value of 1 to 120 printable characters without spaces works; your own order number is ideal. - Keys are remembered per API key for 24 hours.
- A repeat with the same key and the same body gets the first answer again, with the header
Idempotent-Replayed: true. - The same key with a different body is refused with 422
idempotency_key_reused. Use a new key for a new booking. - If the first request is still being handled, the repeat is answered 409
request_in_progress. Wait a moment and send it again. - A request that failed is forgotten, so you can correct it and send it again with the same key.
Cancelling is safe to repeat without a key: cancelling a shipment that is already cancelled answers 200 with the shipment unchanged.
What to retry
| Answer | Retry? |
|---|---|
| No answer, a timeout or a dropped connection | Yes, with the same Idempotency-Key. |
| 429 | Yes, after the seconds in Retry-After. |
| 409 request_in_progress | Yes, after a short wait. |
| 500, 502, 503, 504 | Yes, with back-off: wait longer after each attempt, with a little randomness. |
| 400, 401, 402, 403, 404, 413, 422 | No. Something about the request has to change first. |
The other direction: webhooks
Webhook deliveries are retried too, so your receiver can see the same event more than once. Record the event id of every event you have handled, skip ones you have seen, and answer 2xx to repeats so they stop. See webhooks.