Errors
The form of an error response, the error types and how to handle them.
When a request fails, the API returns an HTTP status code of 400 or more and a JSON body with the same form each time:
{
"error": {
"type": "invalid_request_error",
"code": "parameter_invalid",
"message": "The limit must be between 1 and 100.",
"param": "limit",
"doc_url": "https://docs.afffast.com/errors/parameter-invalid",
"request_id": "req_3kQ9x7WmZpL2vNd8TfYb4A"
}
}| Field | Meaning |
|---|---|
type | The class of the error. See the table below. |
code | A stable code in snake_case. Use it in your code. It never changes for the same problem. |
message | A text for a developer. It can change. Do not parse it. |
param | The name of the parameter or the field that caused the error. It can be missing. |
doc_url | A link to the page of the code with the causes and the fix. |
request_id | The ID of the request. It is also in the response header Request-Id. Send it to support. |
details | A list of places that caused the error. A file import lists the rows (100 at most). |
request_log_url | A link to the request in the logs of the dashboard. It can be missing. |
Error types
| Type | Status codes | Meaning |
|---|---|---|
invalid_request_error | 400, 404, 409, 422 | The request is not valid, or the object does not exist. |
authentication_error | 400, 401 | The key is missing, not valid, or in the URL. |
permission_error | 403 | The key cannot do this: a scope, a role, a mode or a plan limit. |
rate_limit_error | 429 | Too many requests. See Rate limits. |
idempotency_error | 400, 409 | A problem with the Idempotency-Key. See Idempotency. |
api_error | 500 | An error on our side. |
The status codes mean:
- 400: the API cannot read the request (not JSON, a key in the URL, an unknown
Api-Version, a badIdempotency-Key). - 404: the object or the URL does not exist.
- 409: the request conflicts with the state of the data or with an earlier request.
- 422: a value is not valid.
paramnames it.
Handle errors
- Switch on
error.code, not on the message or on the status code alone. - Do not retry a
4xxerror. Fix the request. The only exception is429: wait forRetry-Afterseconds. - Retry a
5xxerror with a growing wait. Use anIdempotency-Keyon aPOST, and send a new key for a new try (see Idempotency). - Keep
request_idin your logs. Send it to support when you ask for help.
The API validates a request before it runs. A request that is not valid never changes data.
All error codes are in Error codes.