# Errors

Every error has the same shape (see [conventions](/guides/conventions/#the-error-shape)): a `code` for your program, a `message` for people, the `status`, the `request_id`, and for a wrong value, `details` with one entry per field.

## The codes

These are every code the API answers. A code never changes for the same cause; a new code is added to this list and to the OpenAPI file together.

| Status | Code | Cause | Fix |
|---|---|---|---|
| 400 | `invalid` | A value is wrong or missing, or a parameter is unknown. Every problem is in details. | Correct the values named in details and send the call again. |
| 400 | `field_required` | A field the task's screen or workflow step requires is empty. | Send each field named in details. |
| 401 | `invalid_token` | No token was sent, or it is wrong, expired or revoked, or its person is no longer a member (or is now a guest). | Send a live token as Authorization: Bearer <token>. Make a new one in Personal settings > API tokens. |
| 402 | `not_in_plan` | The feature isn't in the organisation's plan. | An owner can change the plan in Billing; the message names the plan that has it. |
| 403 | `insufficient_scope` | The token doesn't have the scope this call needs (named in WWW-Authenticate). | Make a token with that scope. |
| 403 | `refused` | The token's person can see the thing but may not do this; the message says why. | Ask whoever the message names for the permission, or use a token of someone who has it. |
| 403 | `api_off` | The organisation's admins have switched the API off. | Ask an organisation admin to switch it on in Organisation settings > API. |
| 403 | `read_only` | The organisation is read-only (over the Free plan's people, or a payment is overdue). | Reading still works. An owner can fix the plan in Billing. |
| 403 | `suspended` | projqo has suspended the organisation. | Contact the organisation's owner. |
| 404 | `not_found` | Nothing is at this address, or the token's person can't see it: the answer is the same. | Check the address and the ids, and that the token's person can open the thing in the app. |
| 405 | `method_not_allowed` | The address exists but not with this method (updates use PATCH; there is no PUT). | Use a method the address lists in the reference. |
| 409 | `conflict` | The thing changed since it was read, or the change clashes with its state. | Read it again and send the change once more. |
| 409 | `archived` | The item (or its project) is archived, so it can't be changed. | Restore it first, or leave it. |
| 409 | `transition_not_allowed` | The transition isn't open from the task's status now, or one of its conditions or checks isn't met; the message gives the workflow's reason. | List the open transitions with GET /tasks/{task}/transitions and pick one of them. |
| 409 | `limit_reached` | A limit was reached (of the plan, or of how many of something one person may have). | The message names the limit; remove something or change the plan. |
| 413 | `too_large` | The body or a file is larger than allowed. | Send less, or a smaller file. |
| 415 | `unsupported_media_type` | The body isn't JSON. | Send JSON with Content-Type: application/json. |
| 422 | `idempotency_key_reused` | The same Idempotency-Key was sent within 24 hours with a different body. | Use a new key for a new request; repeat a request with its own key and the same body. |
| 429 | `rate_limited` | Too many calls in this minute, for the token or for the whole organisation. | Wait the seconds in Retry-After. The RateLimit headers on every answer show what is left. |
| 500 | `internal` | Something went wrong on projqo's side (never your mistake). | Try again; if it keeps happening, contact support and quote the request_id. |

Each entry in `details` names the `field`, says what is wrong in `message`, and has one of these codes: `required`, `invalid_value`, `too_long`, `too_short`, `too_big`, `too_small`, `unknown_parameter`, `invalid_cursor`.

## Workflow and field rules

projqo's own rules refuse a change through the API exactly as they refuse it in the app, with the app's message:

- a transition that isn't open from the task's status, or whose condition or validator isn't met, is `409 transition_not_allowed`: list the open transitions with `GET /tasks/{task}/transitions` and pick one;
- a field the task's screen or the transition's screen requires is `400 field_required`, with the field's key in `details`;
- a value a field doesn't take (an option that isn't the field's, a number out of range, a text too long) is `400 invalid`, one entry in `details` per field, by its key (`summary`, `cf_effort_score`);
- an archived task, project, release or page is `409 archived`;
- a plan's limit (Free's ten people, a guest on Free, the organisation's storage) is `409 limit_reached`;
- any other clash with the item's state (a project's or space's key already taken, a closed sprint, a page published since you read it, the organisation's last owner) is `409 conflict`, and the message says which.

## Hidden and missing look the same

projqo never tells a caller that something exists when the person can't open it. An item in a project the person has no role in answers `404 not_found`, byte for byte the same as an item that was never there.

## Retrying

| Status                                           | Retry?                                                                                                                           |
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| 400, 401, 402, 403, 404, 405, 409, 413, 415, 422 | No: change the request first.                                                                                                    |
| 429                                              | Yes, after `Retry-After` seconds.                                                                                                |
| 500 and other 5xx                                | Yes, a few times, waiting longer each time. For a create, send the same `Idempotency-Key` so the retry can't make a second item. |
