Core concepts
Errors
The error shape, HTTP statuses, and the stable codes your program can switch on.
A failed request answers with an HTTP status outside 2xx and one error object. The code never changes once published, so build your logic on it. The message is written for a person and is safe to show, but its wording may be improved over time.
The error shape
{
"error": {
"code": "LINK_NOT_OPEN",
"message": "This link can no longer be paid, so it was not sent."
},
"requestId": "5b0f0f6e-2c1d-4b63-a7de-0d9a51c2e7f4",
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736"
}error.codestring- A stable, upper-case code. Switch on this.
error.messagestring- One sentence a person can read.
error.detailsobjectOptional- Extra facts for some codes. For
VALIDATION_FAILEDit holdsfields: each bad field with the reasons it was refused. requestIdstring- Quote this when asking for help with a request.
traceIdstring- A second identifier used when following a request across systems.
Validation errors
When the body or the query is wrong, nothing is carried out and details.fields tells you exactly which fields to fix. Nested fields use a dotted path, such as lines.0.quantity.
{
"error": {
"code": "VALIDATION_FAILED",
"message": "title must be longer than or equal to 3 characters",
"details": {
"fields": {
"title": [
"title must be longer than or equal to 3 characters"
],
"colour": [
"This field is not allowed"
]
}
}
},
"requestId": "5b0f0f6e-…"
}HTTP statuses
| Status | Meaning | Retry? |
|---|---|---|
| 200, 201, 202 | Done. The result is in data. | No need |
| 400 | The request is malformed. Code VALIDATION_FAILED. | No. Fix the request. |
| 401 | The API key is missing, wrong, revoked or expired. | No. Fix the key. |
| 403 | The key is not allowed to do this. PERMISSION_REQUIRED or API_KEY_NOT_ALLOWED. | No. Change the key’s permissions. |
| 404 | There is no such record in your organisation. Code NOT_FOUND. | No |
| 409 | It clashes with something that exists or is under way, for example IDEMPOTENCY_IN_PROGRESS or DUPLICATE. | Sometimes. See the code. |
| 422 | The request is well formed but a business rule refuses it. The code says which rule. | No. The message says what to change. |
| 429 | Too many requests. Code TOO_MANY_REQUESTS. | Yes, after a pause. |
| 500 | A fault on our side. Code INTERNAL. | Yes, with the same Idempotency-Key. |
| 502 | A bank or mobile money provider could not be reached. | Yes, with the same Idempotency-Key. |
Codes you will meet everywhere
| Code | Status | Meaning |
|---|---|---|
VALIDATION_FAILED | 400 | A field is missing, the wrong type, out of range, or not one the endpoint knows. |
API_KEY_INVALID | 401 | The key is wrong, revoked or expired. |
PERMISSION_REQUIRED | 403 | The key does not hold the permission the endpoint needs. |
API_KEY_NOT_ALLOWED | 403 | The endpoint is for a signed-in person, not for keys. |
NOT_FOUND | 404 | No such record, or it belongs to another organisation. |
DUPLICATE | 409 | A record with the same unique value already exists. |
IDEMPOTENCY_IN_PROGRESS | 409 | The same request is still running. Try again shortly. |
IDEMPOTENCY_KEY_REUSED | 422 | The key was used before for a different request. |
TOO_MANY_REQUESTS | 429 | Slow down. See Limits. |
INTERNAL | 500 | Something went wrong on our side. It has been logged with your requestId. |
Codes that belong to one feature, such as LINK_PAID or LINK_NOT_OPEN, are listed on that feature's page.
Handling errors well
- Switch on the code, show the message. Never compare against message text.
- Treat an unknown code by its status. New codes are added as features grow; a 4xx you do not recognise is still "do not retry, tell a person".
- Retry only 409 in-progress, 429 and 5xx, with growing pauses and the same Idempotency-Key.
- Log requestId with every failure.