Idempotency and retries
Shipping labels have real-world cost and logistics impact. Duplicate labels cause operational confusion, wasted shipping spend, and inventory tracking errors. The Flex Forward API provides built-in idempotency to prevent this.How idempotency works
ThePOST /labels endpoint uses the idempotencyKey field to ensure that each label creation request is processed exactly once.
First request — the API creates the label and returns HTTP 201:
201 Created
idempotencyKey returns the original result with HTTP 200, without creating a new label:
200 OK (idempotent replay)
Choosing an idempotency key
The key should uniquely identify the intended label creation. Good patterns:| Pattern | Example | Use case |
|---|---|---|
| Order ID | ord-20250301-abc123 | One label per order |
| Order + sequence | ord-20250301-abc123-1 | Multiple labels per order |
| UUID | f47ac10b-58cc-4372-a567-0e02b2c3d479 | General purpose |
After a 400 validation error, the same
idempotencyKey can be reused because no label was created. Fix the request and retry with the same key.Retry strategy
For transient failures (HTTP 500, 502, or network timeouts), retry with exponential backoff:On failure, wait before retrying
Use exponential backoff: 1 second, 2 seconds, 4 seconds, 8 seconds.
Reuse the same idempotency key
Always retry with the same
idempotencyKey as the original request. This ensures no duplicate label is created even if the original request succeeded but the response was lost.Idempotency by endpoint
| Endpoint | Idempotent | Mechanism |
|---|---|---|
POST /labels | Yes | idempotencyKey field — required in every request |
GET /labels/{id} | Yes | Read-only — naturally idempotent |
GET /tracking/{id} | Yes | Read-only — naturally idempotent |
Failure scenarios
Network timeout before receiving a response
Network timeout before receiving a response
The label may or may not have been created. Retry with the same
idempotencyKey. If the label was created, the API returns HTTP 200 with the original result. If not, it creates the label and returns HTTP 201.HTTP 500 Internal Server Error
HTTP 500 Internal Server Error
A transient server error. Retry with backoff using the same
idempotencyKey.HTTP 502 Bad Gateway (courier error)
HTTP 502 Bad Gateway (courier error)
The courier service returned an error. The label is persisted with
status: failed. Check the error message before retrying — some courier errors require changes to the request (e.g., invalid address). For transient courier issues, retry with the same idempotencyKey.HTTP 400 Validation Error
HTTP 400 Validation Error
The request is invalid. Do not retry without fixing the request. The same
idempotencyKey can be reused after correcting the request body because no label was created.