Safe retries
Sending a change again without making it twice, with Idempotency-Key.
A network can fail after TRAKI made a change but before you got the answer. A safe retry lets you send the same change again without making it twice.
The Idempotency-Key header
Send a unique value with every POST:
POST /v1/<part>/… HTTP/1.1
Authorization: Bearer traki_…
Idempotency-Key: 6f1c1c62-3a6a-4cf7-9b55-0d7f1f8f2a1e
Content-Type: application/json- Use a new value for each new change: a UUID is a good choice. It is 8 to 200 letters, digits, dots, colons, dashes or underscores.
- If you retry, send the same value with the same body. TRAKI keeps the first result for 24 hours and answers it again, with the header
Idempotent-Replayed: true. - The same value with a different body is refused with
idempotency_key_reused. - A retry while the first request is still running gets
idempotency_in_progress. Wait a moment and retry again. - Routes that move money or buy something require the header and answer
idempotency_key_requiredwithout it.
GET requests change nothing, so they need no key.
When to retry
| Answer | Retry? |
|---|---|
| No answer, or a network error | Yes, with the same Idempotency-Key |
| 429 | Yes, after Retry-After seconds |
| 500, 502, 503, 504 | Yes, with a growing wait: 1, 2, 4, 8 seconds and so on |
| Any other 4xx | No. Fix the request first |