# Errors

> The error shape, HTTP status codes and common error codes returned by the LemuTickets API

URL: https://docs.lemuai.com/tickets-api/errors

## Error format

Every error from the LemuTickets API has the same shape:
```json
{
  "error": {
    "type": "validation_error",
    "code": "invalid_fields",
    "message": "Some fields are invalid",
    "field_errors": {
      "title": "Field required",
      "requester.email": "Input should be a valid string"
    },
    "request_id": "4f1d9c2b7a6e4e0f8c3b1a2d5e6f7a8b"
  }
}
```

| Field | Description |
|---|---|
| `type` | The kind of error. One `type` per HTTP status (see the table below). |
| `code` | A stable, specific reason, for example `version_mismatch` or `duplicate_external_id`. Use this in your code. |
| `message` | A plain-language description for people. It can change; do not match on it. |
| `field_errors` | Only when specific fields are wrong: an object from field name to problem. Nested fields use dots, for example `custom_fields.order_id`. |
| `data` | Only on some errors: extra details, such as `current_version` on a version conflict or `retry_after` on a rate limit. |
| `request_id` | The id of this request, also in the `X-Request-Id` header. Include it when you contact support. |

The [OAuth token endpoint](https://docs.lemuai.com/tickets-api/authentication#token-endpoint-details) is the one exception: it returns errors in the standard OAuth format.

## Status codes

| Status | `type` | Meaning |
|---|---|---|
| `401` | `unauthorized` | No credentials, or the key or token is wrong, revoked or expired |
| `403` | `forbidden` | The credentials are valid but not allowed to do this |
| `404` | `not_found` | The id or key does not exist, or you are not allowed to see it |
| `409` | `conflict` | The request clashes with something that already exists |
| `412` | `precondition_failed` | The ticket changed since you read it (`If-Match`) |
| `422` | `validation_error` | The body or a parameter is invalid |
| `429` | `rate_limited` | Too many requests; see [rate limits](https://docs.lemuai.com/tickets-api/conventions#rate-limits) |
| `500` | | Something went wrong on our side |

A ticket in a project you cannot access returns `404`, not `403`, so the API never confirms that it exists.

## Common error codes

| Status | `code` | When |
|---|---|---|
| `401` | `unauthenticated` | No API key or token was sent |
| `401` | `invalid_api_key` | The API key is wrong, revoked or expired |
| `401` | `invalid_token` | The OAuth access token is wrong, revoked or expired |
| `403` | `missing_capability` | The key or token lacks a scope. `data.missing` lists the scopes needed |
| `403` | `ip_not_allowed` | The request came from an IP address that is not allowed |
| `403` | `transition_forbidden` | The workflow only lets certain roles, or the assignee, make this transition |
| `403` | `transition_condition` | The ticket does not meet the transition's conditions |
| `404` | `ticket_not_found` | No ticket with this key or id that you can see |
| `404` | `project_not_found` | No project with this key or id |
| `404` | `attachment_not_found` | No attachment with this id that you can see |
| `404` | `webhook_not_found` | No webhook with this id |
| `409` | `duplicate_external_id` | A ticket with this `external_id` already exists. `data` has its `ticket_id` and `key` |
| `409` | `idempotency_mismatch` | An `Idempotency-Key` was reused with a different body |
| `412` | `version_mismatch` | The ticket's version is not the one in `If-Match`. `data.current_version` has the current one |
| `422` | `invalid_fields` | The body or a query parameter failed validation. See `field_errors` |
| `422` | `missing_title` | The ticket title is empty |
| `422` | `project_archived` | The project is archived and takes no new tickets |
| `422` | `invalid_type` | The ticket type does not exist in this project |
| `422` | `invalid_status` | The status does not exist in this ticket's workflow |
| `422` | `invalid_priority` | Priority is not `p1`, `p2`, `p3` or `p4` |
| `422` | `invalid_source` | `source` is not one of the allowed values |
| `422` | `invalid_assignee` | The assignee is not an active member of your organization |
| `422` | `invalid_team` | The team does not exist |
| `422` | `invalid_requester` | The requester does not exist |
| `422` | `invalid_custom_fields` | One or more custom field values are wrong. See `field_errors` |
| `422` | `invalid_if_match` | `If-Match` is not a version number |
| `422` | `invalid_transition` | The ticket cannot move to that status from its current status |
| `422` | `transition_validation` | The transition needs fields or a comment you did not send. See `field_errors` |
| `422` | `missing_target` | A transition request had neither `to_status` nor `transition_id` |
| `422` | `empty_comment` | The comment body is empty |
| `422` | `invalid_link` | A ticket cannot link to itself |
| `422` | `invalid_minutes` | Logged minutes are not between 1 and 1440 |
| `422` | `missing_user` | The caller is not a user (for example a client credentials token), so `user_id` is required |
| `422` | `file_too_large` | The file is over 25 MB |
| `422` | `blocked_file_type` | The file is an executable or script type that is not allowed |
| `422` | `invalid_events` | A webhook event name or pattern matches no event |
| `422` | `invalid_url` | A webhook URL is not `http://` or `https://` |
| `422` | `private_address` | A webhook URL points at a private or local address |
| `422` | `tql_syntax` | The TQL query could not be parsed. `data.position` points at the problem |
| `422` | `tql_field` | The TQL query uses a field that does not exist |
| `429` | `rate_limited` | Too many requests. The `Retry-After` header and `data.retry_after` say how many seconds to wait |

New codes can be added over time. Handle unknown codes by falling back to the HTTP status.

## Handling errors

- **Retry `429`** after the number of seconds in `Retry-After`.
- **Retry `500` and other `5xx` responses** with exponential backoff. They are usually temporary. A `5xx` can come back without the JSON body above, so check the status before parsing. Use an [idempotency key](https://docs.lemuai.com/tickets-api/conventions#idempotency-keys) on creates so a retry never makes a duplicate.
- **On `412`**, get the ticket again, check that your change still applies, and retry with the new version.
- **On `409` `duplicate_external_id`**, the ticket already exists: use the `key` in `data` instead of creating another.
- **Do not retry other `4xx` responses** without changing the request. Read `code` and `field_errors` to see what to fix.
