Errors
Every error has a stable code and a readable message.
Errors return JSON with a stable code you can branch on and a message written for people:
{ "error": { "code": "unauthorized", "message": "missing or invalid API key", "request_id": "req_..." } }Status | Code | What to do |
|---|---|---|
400 |
| Fix the request body or query; the message names the field. A bulk create over your plan's batch size also returns 400. |
401 |
| The API key is missing, wrong or revoked. |
402 |
| You've used this month's trackings. Upgrade, or wait for the next month. |
404 |
| No tracking, webhook or key with that id on your account. |
409 |
| A create with this |
409 |
| The tracking this |
422 |
| We don't track that carrier yet. We record the request, and it moves that carrier up our build queue. |
422 |
| We can't tell the carrier from the number alone. Send |
422 |
| This |
429 |
| Too many requests. Wait for the |
Anything in the 5xx range is on our side: retry with backoff, and include the request_id if you contact us.
Errors in the libraries
Each library turns these into typed errors. They all share a base class that carries the HTTP status, the code, the message and the request_id.
Status | TypeScript | Python | Go | Ruby | PHP |
|---|---|---|---|---|---|
400, 422 |
|
|
|
|
|
401 |
|
|
|
|
|
403 |
|
|
|
|
|
404 |
|
|
|
|
|
429 |
|
|
|
|
|
5xx |
|
|
|
|
|
No response |
|
|
|
|
|
402 |
|
|
|
|
|
409 |
|
|
|
|
|
QuotaExceededError and ConflictError are new in 0.2; in 0.1, branch on code for 402 and 409. Each library page shows the error handling for that language.
Timeouts
A ConnectionError has a code: connection when the request never reached us, timeout when no answer came in time. After a timeout the outcome is unknown: a create may have gone through. Retry it with the same Idempotency-Key, and you get the first tracking back instead of a second one. The libraries' own retries do this for you.
Retrying a create safely
Send an Idempotency-Key header on POST /v1/trackings. A retry with the same key and body returns the tracking the first request created instead of adding a second one. The libraries do this for you. See Pagination, retries and idempotency.
Watching your quota
GET /v1/account/usage returns trackings_used, trackings_limit and trackings_remaining for the current month (UTC), with period_end saying when it resets. Check it before a create fails with 402 quota_exceeded. See Rate limits and plans.