Skip to main content

Retries and idempotency

Networks fail. If your request times out, you can't tell whether Axis received it, so you can't tell whether retrying would do the thing twice: order twice, buy two top-ups, or charge twice.

Send an Idempotency-Key header on a POST and it becomes safe to retry: Axis does it once, and every repeat with the same key gets the first answer back instead of doing it again.

How to use it​

  • Make a new unique key for each operation you mean to do once, such as a UUID. Keep it with the job, so a retry reuses it.
  • Up to 255 characters.
  • Keys are remembered for 24 hours.
  • Every POST accepts one. Use it on anything that charges or orders: POST /orders, POST /pools, POST /sims/{id}/top-ups, POST /pools/{id}/top-ups. It's just as useful on the SIM actions.
curl -X POST https://app.zentarinetworks.com/api/v1/orders \
-H "Authorization: Bearer $AXIS_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7" \
-d '{ "type": "digital", "quantity": 10 }'

What you get back​

SituationAnswer
First time with this keyDone as normal
Same key, same request, first one finishedThe first answer again, with Idempotent-Replayed: true. Nothing is done twice
Same key, same request, first one still running409 idempotency_in_progress: wait a moment and retry
Same key, different request (method, path or body)422 idempotency_key_reused

When to retry​

AnswerRetry?
No answer, a timeout, a dropped connectionYes, with the same key
429Yes, after Retry-After seconds
500, 502, 503Yes, after a short pause (say 1s, then 5s, then 30s), with the same key
409 idempotency_in_progressYes, after a moment
Any other 4xxNo: change the request first (Errors)

GET, PUT, PATCH and DELETE are naturally safe to repeat: doing them twice leaves things the same as doing them once.