Get started

Idempotency

Retry an order after a timeout without ever buying twice.

Why it matters

Networks fail at the worst moment. If your request to buy eSIMs times out, you can't tell whether Burj received it. Retrying blindly could buy the eSIMs twice; not retrying could leave a traveller without one.

The Idempotency-Key header removes the guesswork on /order/create: retry as often as you need, and the order is placed at most once.

One key per order

  • Create one key per order the user means to place, ideally a UUID v4. 1 to 100 visible ASCII characters.
  • Store it with your order before you call Burj, so a crash or redeploy retries with the same key.
  • Reuse it for every retry of that order. A new order gets a new key.

Replays

You sendYou get
Same key + same body within 24 hThe first answer again, with header Idempotent-Replayed: true. Nothing is bought twice.
Same key while the first request is still runningHTTP 409 IDEMPOTENCY_IN_PROGRESS: retry in a few seconds.
Same key + a different bodyHTTP 422 IDEMPOTENCY_KEY_REUSED: a bug on your side. Use a new key for a new order.
An empty, too long or non-ASCII keyHTTP 400 INVALID_IDEMPOTENCY_KEY

What is not stored

Failed orders don't keep the key. If the order failed (for example PROVIDER_ORDER_FAILED, where nothing was charged), the same key can be used to try again, and that retry really places the order.

Replays work for 24 hours, so finish your retries within that window, and never reuse an old key for a new order. Without the header, /order/create works as before, with no protection against double orders.

Retrying safely

Retry on timeouts, network errors and these codes, always with the same key:

  • IDEMPOTENCY_IN_PROGRESS (409): the first attempt is still running.
  • PROVIDER_ORDER_FAILED (502): nothing was charged, try again.
  • INTERNAL_ERROR (500), RATE_LIMITED (429): wait, then try again.

Don't retry business errors such as INSUFFICIENT_BALANCE or PACKAGE_NOT_FOUND: fix the cause first.