Idempotency
Networks drop. Timeouts happen. 503s happen. Idempotency keys make POSTs safe to retry without creating duplicate shipments.
The Idempotency-Key header
Send a unique Idempotency-Key on every POST — UUID v4 recommended. The first request is processed normally and the result is cached against the key; subsequent calls with the same key return the cached response without re-running the operation.
curl https://imileexpress.com/api/v1/shipments \ -H "Authorization: Bearer mk_test_rh9ABekJfP31cN7sQ8jKvLwY" \ -H "Idempotency-Key: 5f3c7a44-2d2b-4f63-a8b1-9c0f1d8e7b62" \ -H "Content-Type: application/json" \ -d '{ "service_tier_id": "HKASTDGGSTCM", "recipient": {...}, ... }' # Same key + same method, path and body → identical response, no duplicate shipment. # Same key + different body, or on a different endpoint → 409 Conflict (sysCode 1500003)
⚠ One key = one order
An Idempotency-Key identifies one logical request — not your account, and not your integration. Every new order needs a new, unique key. Hard-coding a single key in a script or an API client (Postman, Insomnia) is the most common integration mistake we see.
The cache stores failed responses too — with exceptions: account-state rejections are never cached. A payload error (say a 400 on an invalid address) is cached, so the same key returns the same 400. But rejections that depend on your account — insufficient balance, credit limit, overdue-invoice freeze — are not cached: once you top up or settle, retrying with the same key re-evaluates your account and the order goes through. A rejection because the quote changed before order creation (409, sysCode 1500015) is not cached either: the response carries the current quote in data.current_option, so confirm it and retry, with the same key if you like.
In practice: generate a UUID v4 at the moment you build the request and store it alongside your order record, then reuse it only when retrying that same order. In Postman, set the header value to {{$guid}} so a new key is generated on every send.
Per-endpoint requirement
Not every mutating endpoint needs an Idempotency-Key. Create-style endpoints (which mint a new resource / debit the wallet) require it; endpoints that are naturally idempotent (delete, cancel, rotate) treat it as optional.
| Endpoint | Idempotency-Key | Why |
|---|---|---|
| POST /api/v1/shipments | REQUIRED | Creates a shipment & debits the wallet — retries must not duplicate. |
| POST /api/v1/webhooks | REQUIRED | Creates a new webhook endpoint — retries must not duplicate. |
| POST /api/v1/pickups | REQUIRED | Arranges a pickup — retries must not book twice; use a new key after every new preview. |
| POST /api/v1/pickups/self-dropoffs | REQUIRED | Declares a self drop-off — retries must not declare twice; after 24 hours the same key with the same shipments returns the original records. |
| POST /api/v1/pickups/preview | NOT USED | Prices only and saves nothing; every call is a fresh quote. |
| POST /api/v1/pickups/{id}/cancel | OPTIONAL | Naturally idempotent — a repeat answers already_cancelled. The same key replays the first response while it is cached. |
| DELETE /api/v1/webhooks/{id} | OPTIONAL | Naturally idempotent — deleting twice has the same effect. |
| POST /api/v1/shipments/{id}/cancel | OPTIONAL | Naturally idempotent — cancelling an already-cancelled shipment is a no-op. |
| POST /api/v1/webhooks/{id}/rotate | OPTIONAL | Naturally idempotent — converges on resource state, safe to retry. |
24-hour window
Cached responses live for 24 hours — successes (2xx) and payload-level client errors (4xx) alike. After that, the same key is treated as a fresh request. Five kinds of response are never cached, so retrying with the same key re-runs the operation: server errors (5xx); account-state rejections — sysCode 1500009 (insufficient available balance), 1500012 (overdue-invoice freeze), 1500013, 1500014 and 1500016 (credit floor / limit); and a cancel refused because an interception request is in progress or a pickup holds the shipment — sysCode 1500032 (withdraw the request, then retry with the same key) and 1500116 (cancel the pickup, or contact customer service if a self drop-off declaration holds the shipment, then retry with the same key) and 1500022 (the partner carrier could not cancel, for example already collected; retrying with the same key is safe, the cancel checks the carrier status first and treats an already-cancelled order as success); and a rejection of a USD-wallet account because of a switch or list state — sysCode 1500203 (it happens before anything is written; once the state allows it, retry with the same key); and a quote that changed before order creation — sysCode 1500015 (the response carries the current quote in data.current_option; confirm it and retry, with the same key if you like).
Conflicts
A key is bound to the HTTP method, path and body of the first request that used it. Same key with a different body, or on a different endpoint → rejected with 409 IDEMPOTENCY_KEY_REUSED (sysCode 1500003) and the request is not run. Re-sending the same method, path and body replays the stored response.