# Errors

A failed request gets an HTTP status and a JSON body. The body names the error with a code, never a sentence, so your
software decides what to do from the status and the code, not from text.

```json title="Response"
{
  "error": "validation_error",
  "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
  "details": { "name": "required" }
}
```

- `error` is the code.
- `trace_id` identifies the request on our side. Send it with a support question about a failure.
- `details` maps each wrong field, by its JSON name, to a code that says what is wrong with it. It is `null` when there is
  nothing to name.

## Statuses

| Status | Code                         | When                                                                                | What your software does next                                      |
| ------ | ---------------------------- | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| 400    | `invalid_request`            | the token request is missing its client ID or secret, or sends both ways            | repair the request, do not retry                                  |
| 400    | `validation_error`           | a field is wrong; `details` names it                                                | repair the named field                                            |
| 400    | `invalid_target`             | the token request names a resource that is not this API                             | repair the request, do not retry                                  |
| 401    | `invalid_client`             | the client ID or secret is wrong, or the client is disabled                         | check the secret, do not retry                                    |
| 401    | `unauthorized`               | no Bearer token was sent, or the token was revoked, or its integration was disabled | send a valid token, do not retry the same one                     |
| 401    | `token_invalid`              | the token is malformed, has a bad signature or has expired                          | exchange the secret for a new token, then retry once              |
| 403    | `forbidden`                  | the token is valid, but this integration may not make this call                     | do not retry                                                      |
| 404    | `not_found`                  | the thing does not exist, or it belongs to another Customer                         | do not retry; we answer the same for both on purpose              |
| 409    | `conflict`, `already_exists` | the request clashes with something that exists, such as a duplicate name            | change the value, then retry                                      |
| 429    | `rate_limited`               | the integration or its Customer is over its budget                                  | wait for the `Retry-After` seconds, then retry                    |
| 500    | `internal_error`             | our fault                                                                           | retry with backoff, then stop; send the `trace_id` if it persists |
| 503    | `service_unavailable`        | a service we depend on is down                                                      | retry with backoff                                                |

A 401 carries `WWW-Authenticate`: `Basic` on `invalid_client`, and `Bearer` on the others.

## Rate limits

Each integration may make 300 requests a minute. All integrations of one Customer share 600 a minute. A response to a
request made with a valid token carries two headers:

- `X-RateLimit-Limit`: the budget for the current minute.
- `X-RateLimit-Remaining`: what is left of it.

A request refused with 429 carries `Retry-After`, in seconds. A request refused with 401 for an invalid token carries
neither header, because it never reached the budget.