> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cufea.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors

> The problem document and the catalog of error codes.

Every error is `application/problem+json` ([RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)):

```json theme={null}
{"type":"urn:cufea:problem:validation_error","title":"Request validation failed","status":422,
 "code":"validation_error","detail":"The request is not valid; see `errors` for the offending fields.",
 "request_id":"88272d6eb903438690d3193e3113270a",
 "errors":[{"loc":["body","customer"],"msg":"Field required"}]}
```

| Field | Meaning |
| - | - |
| `type` | Stable URI of the problem kind: `urn:cufea:problem:` and the code. |
| `title` | Short, human-readable summary of the problem kind. |
| `status` | The HTTP status code. |
| `code` | **Stable machine-readable code: branch on it.** |
| `detail` | Explanation of this occurrence. |
| `request_id` | The `X-Request-ID` response header. Quote it when asking for support. |
| `errors` | On `validation_error`: the offending fields. Your values are never echoed. |
| `dian` | Present only when the DIAN rejected a document. |

Some codes add their own fields: `promotion_refused` carries `missing`, `event_not_allowed`
carries `next_step` and `idempotency_secret_withheld` carries `endpoint_id`.

## Catalog

The codes the contract documents, by HTTP status. Each endpoint's page in the
[API reference](https://docs.cufea.com/en/api-reference/introduction.md) lists the ones it can answer.

### 401 and 403

| Code | Cause | What to do |
| - | - | - |
| `unauthorized` (401) | Missing or invalid API key (or partner key). | Send `Authorization: Bearer <key>` with a valid key. |
| `stage_not_allowed` | The stage is not this key's: a key reads and writes its own stage only. | Use a key of that stage. |
| `stage_closed` | The key's stage is not open for the tenant (production before the promotion). | [Promote](https://docs.cufea.com/en/production.md) the tenant first. |
| `tenant_suspended` | The tenant is suspended. | Contact Cufea support with the `request_id`. |
| `partner_tenant_limit` | The partner reached its tenant limit. | Contact Cufea. |

### 404

| Code | Cause |
| - | - |
| `document_not_found` | No such invoice, note or event for this tenant and stage. |
| `api_key_not_found` | No such key for this tenant. |
| `webhook_not_found` | No such webhook endpoint for this tenant. |
| `tenant_not_found` | No such tenant for this partner. |
| `certificate_not_stored` | No certificate is stored for the stage. |
| `issuer_not_configured` | The issuer is not configured. |
| `numbering_range_not_configured` | The numbering range is not configured. |

### 409

| Code | Cause | What to do |
| - | - | - |
| `tenant_not_configured` | The tenant lacks configuration for this stage. | `GET /v1/tenant/configuration` lists what is missing. |
| `reference_conflict` | Another document of this kind and stage already carries the `reference`. | Find it with `GET /v1/documents?reference=...&kind=...`. |
| `idempotency_in_progress` | A request with the same `Idempotency-Key` is still running. | Retry later with the same key. |
| `idempotency_secret_withheld` | The webhook endpoint `endpoint_id` was already created by this key; its secret is not shown again. | Delete it and create a new one if the secret was lost. |
| `numbering_range_exhausted` | The numbering range is used up. | Add a new range. |
| `numbering_range_changed` | The range was replaced while the invoice was being created. | Retry. |
| `numbering_range_in_use` | The new range would strand numbers already issued. | See [Numbering](https://docs.cufea.com/en/guides/numbering.md). |
| `invoice_not_accepted` | The referenced invoice is not accepted by the DIAN. | Notes and events need an accepted invoice. |
| `invoice_closed_for_notes` | An accepted 033/034 event closed the invoice to notes. | |
| `invoice_unreadable` | The stored invoice is not readable as a sales invoice. | |
| `document_not_accepted` | The DIAN has not accepted the document yet. | Wait for the final state. |
| `attached_document_unavailable` | No stored DIAN answer allows building the AttachedDocument yet. | Refresh the invoice first. |
| `email_unavailable_in_stage` | The sandbox and DIAN test stages never email. | See [Delivery](https://docs.cufea.com/en/guides/delivery.md). |
| `event_needs_issuer_buyer` | A RADIAN event needs the buyer to be the issuer (a sandbox key may use a third-party buyer). | |
| `event_not_allowed` | The event chain or timing rules refuse the event; `next_step` says what comes next. | |
| `cannot_revoke_current_key` | A request cannot revoke the key it uses. | Revoke it with another key. |
| `issuer_nit_locked` | The tenant was provisioned by a partner and its NIT cannot change. | |
| `tenant_nit_conflict` | The NIT already has a tenant with other data. | See [Partners](https://docs.cufea.com/en/partners.md). |
| `stage_closed` | A production key before the tenant is promoted. | |

### 413 and 422

| Code | Cause |
| - | - |
| `payload_too_large` (413) | The body is too large (a certificate over 96 KB). |
| `validation_error` | The request is malformed; `errors` lists the fields. |
| `invoice_invalid`, `note_invalid`, `event_invalid` | The body breaks an invoice, note or event rule; `detail` names it. |
| `idempotency_key_reused` | The `Idempotency-Key` was used for a different request. |
| `numbering_prefix_unknown` | The stage has no range for that `prefix`. |
| `numbering_range_not_in_force` | The range is not in force at the issue date. |
| `invalid_cursor` | The `cursor` is not a `next_cursor` of this list with these filters. |
| `issuer_invalid`, `numbering_range_invalid`, `secret_invalid`, `webhook_invalid`, `tenant_invalid` | The body breaks a DIAN or configuration rule; `detail` names it. |
| `certificate_invalid` | The `.p12` cannot sign: wrong password, not PKCS#12, expired, too many iterations... |
| `promotion_refused` | A production precondition is missing; `missing` lists them. |
| `pdf_invalid` | `pdf_base64` is not a PDF in base64. |
| `package_too_large` | The email ZIP would be over the 2 MB of Anexo 1.9 §9.1. |
| `email_rejected` | The email provider refused the address. |

### 429, 5xx

| Code | Cause | What to do |
| - | - | - |
| `rate_limited` (429) | The API key is over its quota. | Wait `Retry-After` seconds. See [Rate limits](https://docs.cufea.com/en/rate-limits.md). |
| `store_error` (500) | The document store failed. A number already reserved is lost, never reused. | Retry with the same `Idempotency-Key`. |
| `queue_error` (500) | The job queue failed. | Retry the send. |
| `dian_unavailable` (502) | The DIAN gave no usable answer; the stored state is unchanged. | Try again later. |
| `email_unavailable` (502) | The email provider did not answer; nothing was sent. | Try again later. |
| `service_unavailable` (503) | The server runs without the service this route needs. | Try again later and quote the `request_id`. |

A create or send retried with its `Idempotency-Key` after a `429` or a `5xx` is safe: see
[Idempotency](https://docs.cufea.com/en/idempotency.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.