# Errors

> The error response shape and the stable error code catalogue

Source: https://app.relvoerp.com/docs/product/guides/errors/

Every error from `/api/v1/public` uses the same JSON envelope. This includes validation failures, domain rule violations and auth rejections.

```json
{
  "code": "validation_failed",
  "message": "Request validation failed",
  "request_id": "019f5334-1e22-7082-a665-b54b0e93bfba",
  "correlation_id": "019f5334-1e22-7082-a665-b54b0e93bfba",
  "params": {
    "validation_errors": [
      { "loc": ["body", "currency"], "type": "missing", "message": "Field required" }
    ]
  },
  "is_transient": false
}
```

| Field | Description |
|---|---|
| `code` | A stable, machine-readable `snake_case` code. You can safely branch on it in your integration. |
| `message` | A human-readable description. Its wording may change, so don't parse it. |
| `request_id` | The ID of this HTTP request. Include it when you contact support. |
| `correlation_id` | Groups related requests, such as a request and the async work it triggers. |
| `params` | Structured detail about the failure. It is always an object, and may be `{}`. |
| `is_transient` | `true` means the same request may succeed if you retry it later. `false` means a retry fails the same way unless you change the request. |

## Cross-cutting codes

| Status | `code` | Meaning |
|---|---|---|
| `400` | `bad_request` | The request is malformed. |
| `400` | `idempotency_key_required` | A POST without an `Idempotency-Key` header. See [Idempotency](https://app.relvoerp.com/docs/product/guides/idempotency.md). |
| `400` | `invalid_idempotency_key` | The `Idempotency-Key` value is malformed. |
| `400` | `invalid_if_match` | The `If-Match` value is not `W/"<version>"`. |
| `400` | `invalid_cursor` | The pagination `cursor` is malformed or expired. |
| `401` | `unauthenticated` | The token is missing or invalid. The response carries a `WWW-Authenticate` header. |
| `403` | `forbidden` | You are authenticated, but not allowed to perform this action. |
| `403` | `sandbox_organization_required` | Use an API key from an active sandbox workspace for the sandbox API. |
| `403` | `insufficient_scope` | The token lacks every scope the operation accepts. See [Authentication](https://app.relvoerp.com/docs/product/guides/authentication.md). |
| `403` | `ip_not_allowed` | The caller's IP is not on the token's allow-list. |
| `404` | `not_found` | The resource doesn't exist or isn't visible to your organization. |
| `405` | `method_not_allowed` | The HTTP method is not supported on this path. |
| `406` | `not_acceptable` | The `Accept` header asks for a format the operation cannot produce. |
| `409` | `conflict` | The request conflicts with the resource's current state. |
| `409` | `idempotency_key_reused` | The `Idempotency-Key` was already used with a different request body. |
| `409` | `idempotency_key_in_progress` | The first request with this `Idempotency-Key` is still running. Wait briefly, then retry with the same key. |
| `410` | `gone` | The resource or operation was permanently removed. |
| `412` | `version_conflict` | The `If-Match` version is stale. `params.current_version` holds the current version. |
| `413` | `payload_too_large` | The body is too large. `params.max_bytes` holds the limit. |
| `415` | `unsupported_media_type` | Send `Content-Type: application/json`. |
| `422` | `validation_failed` | The body or query failed validation. See `params.validation_errors`. |
| `422` | `metadata_invalid` | `metadata` breaks a limit (50 keys, 40-character keys, 500-character values). `params.reason` says which. |
| `428` | `precondition_required` | A PATCH, PUT, DELETE or action was sent without the required `If-Match` header. |
| `429` | `rate_limited` | Too many requests. Wait for `Retry-After` seconds. |
| `500` | `internal_error` | An unexpected error. Check `is_transient`. |
| `502` | `bad_gateway` | An upstream provider returned an invalid response. Retry with backoff. |
| `503` | `service_unavailable` | A dependency is temporarily unavailable. Retry with backoff. |
| `503` | `concurrency_retry` | A concurrent write collided with this one. Retry the same request, with the same `Idempotency-Key`. |
| `504` | `gateway_timeout` | An upstream provider did not answer in time. Retry with the same `Idempotency-Key`. |
| `422` | `invalid_date_window` | The requested start/end date window is invalid; correct its boundaries. |
| `409` | `invoice_line_total_discount_review_required` | Remove the total discount before editing a line amount or currency, then review and reapply it. |

Resource-specific codes (for example `webhooks_endpoint_not_found`) are listed on each resource's page.

## Report codes

Every operation under `/reports/` can also return these:

| Status | `code` | Meaning |
|---|---|---|
| `400` | `reporting_money_fx_rate_not_found` | No exchange rate on or before the anchor date converts an amount into `reporting_currency`. `params` names `from_currency`, `to_currency` and `anchor_date`. Load the rate or choose another `reporting_currency`. |
| `400` | `reporting_*` | Another reporting rule rejected the inputs. The code names the rule. |
| `400` | `invalid_cursor` | On the receivables-aging invoice list: the `cursor` was altered, or was sent with different filters (`customer_id`, `as_of`, `group_key`, `reporting_currency`, `contract_id`) than the page that issued it. |
| `422` | `validation_failed` | An unknown enum value or timezone, `date_from` after `date_to`, or a `limit` out of range. |
| `500` | `report_unavailable` | The report could not be computed. This is a server-side fault, not something the request can fix. Retrying is safe. |

## Invoices, credit notes and debit notes

| Status | `code` | Meaning |
|---|---|---|
| `404` | `invoice_not_found` | The invoice does not exist in your organization. |
| `404` | `invoice_line_not_found` | The invoice line does not exist on this invoice. |
| `404` | `invoice_line_group_not_found` | The invoice line group does not exist on this invoice. |
| `404` | `invoice_version_not_found` | The requested invoice version does not exist. |
| `404` | `credit_note_not_found` | The credit note does not exist in your organization. |
| `404` | `debit_note_not_found` | The debit note does not exist in your organization. |
| `404` | `fiscal_artifact_not_found` | The document exists but has no stored PDF or XML yet; `params.kind` names which one. Try again once the document is issued. |
| `503` | `fiscal_artifact_unavailable` | Document storage is temporarily unavailable (`is_transient: true`); retry later. |
| `422` | `invoice_billing_entities_not_paired` | Only one of `billing_entity_id` and `issuer_billing_entity_id` was sent; send both or neither. |
| `422` | `invoice_update_empty` | The invoice update body changes no field. |
| `422` | `invoice_line_update_empty` | The line update body changes no field. |
| `422` | `invoice_line_group_update_empty` | The line group update body changes no field. |
| `422` | `invoice_field_not_clearable` | The body sets a required invoice field to `null`; `params.field` names it. |
| `422` | `invoice_line_group_field_not_clearable` | The body sets a required line group field to `null`; `params.field` names it. |
| `422` | `invoicing_invoice_line_input_invalid` | A line in the request is invalid. |
| `409` | `invoicing_invoice_draft_edit_lifecycle_conflict` | The invoice is no longer a `draft`, so it cannot be edited. |
| `409` | `invoicing_invoice_draft_resource_removal_conflict` | The resource cannot be removed from the draft, for example a group that still has lines. |
| `409` | `invoicing_invoice_cancellation_lifecycle_conflict` | Only a `draft` can be cancelled. |
| `409` | `invoicing_invoice_opening_blocked` | The draft cannot be issued yet. `params.blocking_codes` lists the reasons. `issuer_fiscal_registration_missing` means the issuer needs an active fiscal registration. `issuer_fiscal_connection_unresolved` means Relvo could not select an active fiscal provider connection for the issuer. |
| `409` | `invoicing_invoice_line_fiscal_basis_missing` | A line lacks the fiscal basis needed to duplicate the invoice. |
| `409` | `invoicing_next_credit_note_lifecycle_status_invalid` | The credit note is not in the status the operation requires. |
| `409` | `invoicing_next_debit_note_lifecycle_status_invalid` | The debit note is not in the status the operation requires. |
| `409` | `invoicing_next_credit_note_fiscal_status_invalid` | The credit note's fiscal status does not allow the operation. |
| `409` | `invoicing_next_debit_note_fiscal_status_invalid` | The debit note's fiscal status does not allow the operation. |
| `409` | `invoicing_next_credit_note_source_stale` | The source invoice changed after the credit note was drafted; re-read it and draft again. |
| `409` | `invoicing_next_correction_note_source_invoice_invalid` | The source invoice cannot be corrected by a note. |
| `422` | `invoicing_next_debit_note_tax_rate_unsupported` | The tax rate is not accepted for debit notes. |

## Payments and payment methods

| Status | `code` | Meaning |
|---|---|---|
| `422` | `invalid_range` | `received_at_from` is after `received_at_to` on `GET /payments`. |
| `404` | `payment_not_found` | No payment with this id in your organization. |
| `404` | `customer_not_found` | The customer doesn't exist in your organization or is inactive. |
| `404` | `billing_entity_not_found` | The billing entity doesn't belong to the customer in the path. |
| `404` | `payment_method_not_found` | No payment method with this id in your organization. |
| `404` | `payment_method_assignment_not_found` | The customer payment method doesn't belong to the customer in the path. |
| `409` | `payment_method_conflict` | The change conflicts with the method's current state, or a concurrent write won the race. Re-read and retry. |
| `409` | `payment_method_inactive` | The payment method is inactive; inactive methods are terminal. |
| `409` | `payment_method_assignment_inactive` | The customer payment method is inactive; inactive assignments are terminal. |
| `409` | `billing_entity_inactive` | The billing entity is not an active customer relationship. |
| `409` | `payment_method_provider_mismatch` | The method's provider differs from the billing entity's collection provider. |
| `422` | `payment_method_invalid` | The method's fields are not a valid combination (for example `offline` with a provider). |
| `422` | `payment_method_reference_unusable` | The referenced bank account or provider connection is missing, inactive or of another provider. |
| `422` | `payments_payment_method_bank_account_required` | A Relvo-collected `bank_transfer` method needs a `bank_account_id`. |
| `422` | `payments_payment_method_bank_account_incomplete` | The bank account lacks fields a payer needs; `params.missing` names them. |
| `422` | `payments_payment_method_bank_account_currency_unsupported` | The bank account's currency is not one the method supports. |

## Metering, seat events and seat metrics

| Status | `code` | Meaning |
|---|---|---|
| `422` | `invalid_timestamp` | A time filter (`GET /usage-events`, `GET /seat-events`, `GET /currency-conversions`, evaluation timeframes) is not an RFC 3339 instant with an offset. |
| `422` | `invalid_range` | A `*_from` filter is after its `*_to` (`GET /usage-events`, `GET /seat-events`, `GET /payments`). |
| `404` | `seat_event_not_found` | No seat event with that id in this organization. |
| `404` | `seat_metric_not_found` | The seat metric is missing or already deleted (`PATCH`). |
| `404` | `seat_metric_not_on_contract` | `GET /seat-events/count`: the seat metric is not defined on that contract (or any of its revisions) in this organization. |
| `409` | `seat_metric_in_use` | `DELETE /catalog/seat-metrics/{id}`: seat prices or open contracts still read quantity from the metric. |
| `404` | `usage_event_not_found` | No usage event with that id in this organization. |
| `404` | `usage_event_receipt_not_found` | No usage event receipt with that id in this organization. |

Per-item results of `POST /seat-events` carry `idempotency_key_reused` when an
item's key was already used with a different body; nothing is written for that
item. The same key with the same body is reported as a duplicate.

## Customers, billing entities and contacts

| Status | `code` | Meaning |
|---|---|---|
| `409` | `customer_code_not_unique` | Another customer in your organization already uses this `code`; pick a different one. |
| `422` | `customer_rejected` | The customer create or update breaks a customer rule; check the fields you sent. |
| `422` | `billing_entity_rejected` | The billing entity create, update or delete breaks a billing entity rule. |
| `422` | `billing_entity_is_issuer` | Your organization's own issuing billing entity cannot be deleted. |
| `422` | `billing_profile_archived` | The billing profile is archived, so it cannot be updated. |
| `422` | `billing_profile_rejected` | The billing profile update breaks a billing profile rule. |
| `422` | `contact_rejected` | The contact create or update breaks a contact rule. |

## Contracts and contract documents

| Status | `code` | Meaning |
|---|---|---|
| `403` | `contract_forbidden` | The token may not access contracts of this organization. |
| `404` | `contract_not_found` | The contract, or a resource it references, does not exist in your organization. |
| `404` | `contract_amendment_reconciliation_not_found` | The amendment reconciliation does not exist. |
| `404` | `contract_document_not_found` | The contract document does not exist on this contract. |
| `409` | `contract_not_active` | The contract must be active for this action. |
| `409` | `contract_price_not_active` | A price bound to the contract is not active; activate it or bind another price. |
| `409` | `contract_state_conflict` | The contract's current state does not allow this action; re-read the contract. |
| `413` | `contract_document_too_large` | The PDF exceeds 20 MiB. |
| `415` | `contract_document_content_type_invalid` | Send the document with `Content-Type: application/pdf`. |
| `422` | `contract_document_pdf_invalid` | The upload is not an intact PDF of at most 20 MiB. |
| `422` | `contract_invalid` | The contract change violates a contract rule. |
| `422` | `contract_unreadable` | The contract could not be read; contact support with the `request_id`. |

## Imports

| Status | `code` | Meaning |
|---|---|---|
| `403` | `contract_import_requester_not_authorized` | No organization administrator stands behind this upload, so the import was refused. |
| `404` | `contract_import_not_found` | The contract import does not exist in your organization. |
| `422` | `contract_import_pdf_invalid` | The contract PDF could not be read; resend the original file. |

## FX (`/currency-conversions`)

| Status | `code` | Meaning |
|---|---|---|
| `404` | `currency_conversion_not_found` | No official conversion rate is available for this currency pair at that instant. |
| `422` | `currency_pair_invalid` | `base_currency` and `quote_currency` must differ. |

## Organization

| Status | `code` | Meaning |
|---|---|---|
| `404` | `organization_not_found` | The token's organization does not exist. |
| `404` | `invitation_not_found` | The invitation does not exist, or its organization is gone. |

## Commercial references

| Status | `code` | Meaning |
|---|---|---|
| `404` | `parsed_commercial_reference_not_found` | The parsed commercial reference does not exist in your organization. |

## Messaging

| Status | `code` | Meaning |
|---|---|---|
| `404` | `message_not_found` | The message does not exist in your organization. |

## Financial credits (`/credits/*`)

| Status | `code` | Meaning |
|---|---|---|
| 403 | `credits_forbidden` | Current organization membership or token authority does not permit the operation. |
| 404 | `credits_not_found` | Credit grant or a required customer, billing entity, metric or purchase reference is unavailable in this organization. |
| 404 | `credits_scope_mismatch` | The requested credit scope does not match its organization, customer or billing entity. |
| 422 | `credits_invalid` | A credit amount, availability window, purchase invoice or other financial term is invalid. |
| 422 | `credits_asset_mismatch` | Credit currencies or metrics do not match exactly. |
| 409 | `credits_capacity_exceeded` | The operation exceeds authoritative credit capacity. |
| 409 | `credits_not_spendable` | The grant is revoked, scheduled or expired at the relevant instant. |
| 409 | `credits_transition_invalid` | The current lifecycle or outstanding invoice reservations block this operation. |
| 409 | `credits_concurrent_write` | Credits changed concurrently; recompute the operation and retry with the same request key. |
| 409 | `credits_grant_stale_version` | A correction was built against an outdated grant version. |

Revocation uses the standard `428 precondition_required` and `412 version_conflict`
codes for missing or stale `If-Match`. Idempotency and cursor failures use the
cross-cutting codes above. A purchase invoice draft failure rolls back the grant too.

## Validation errors

`params.validation_errors` is a list of `{loc, type, message}` objects. `loc` is the path to the invalid field. The list is capped at 100 entries. When the cap is hit, `params.truncated` is `true`.

## Optimistic concurrency

Every mutable resource returns its `version` in the body and as an `ETag: W/"<version>"` header. To change a resource, send that value back in `If-Match`. Each failure has its own code:

- If `If-Match` is missing, the response is `428 precondition_required`.
- If it is malformed, the response is `400 invalid_if_match`.
- If it is stale, the response is `412 version_conflict`. Re-read the resource, then retry using `params.current_version`.

## Quotes and stable credit grants

| Status | `code` | Meaning and recovery |
|---|---|---|
| 400 | `invalid_quote_query` | The quote or template filters are invalid. Correct the named filters; keep the cursor bound to the same query. |
| 400 | `invalid_quote_request` | The quote body is invalid. Check required fields, supported names, exact decimal strings and body limits. |
| 409 | `quote_identity_unavailable` | Original quote identity is unavailable. Reconcile its creation evidence before listing it. |
| 404 | `quote_not_found` | The quote is missing or is not available in this organization. |
| 409 | `quote_presentation_unavailable` | The retained quote cannot be presented completely. Restore its required presentation evidence before retrying. |
| 409 | `quote_template_creator_unknown` | The template has no retained original creator. Reconcile its creation evidence before listing it. |
| 503 | `quote_write_temporarily_unavailable` | The quote write could not complete reliably. Retry the identical request with its original Idempotency-Key. |
| 422 | `retired_query_parameter` | A removed credit-grant filter was supplied. Use contractId instead of billingScheduleId. |
| 400 | `unsupported_quote_version` | The selected quote version profile is unsupported. Omit Sequence-Version or select 2024-07-30. |
