Skip to the content
YallaRoute

Help · Developers: API keys and webhooks

Idempotency keys and safe retries

Send an Idempotency-Key header, such as your order number, with every booking. If the request is repeated with the same key and the same body within 24 hours, the first answer comes back with Idempotent-Replayed: true and nothing is booked twice. The same key with a different body is refused.

Updated

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-Key with POST /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

AnswerRetry?
No answer, a timeout or a dropped connectionYes, with the same Idempotency-Key.
429Yes, after the seconds in Retry-After.
409 request_in_progressYes, after a short wait.
500, 502, 503, 504Yes, with back-off: wait longer after each attempt, with a little randomness.
400, 401, 402, 403, 404, 413, 422No. 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.

Try it in your own workspace

A new workspace has the Scale features for its first 14 days. Open one and follow this article with your own data.