Skip to content

Sign and submit an invoice to Hacienda (ATV)

POST
/v1/hacienda/submit/{invoiceId}
curl --request POST \
--url https://api.emite.cr/v1/hacienda/submit/01a00c73-5c07-7bb5-8b9e-d20f16537e42 \
--header 'Authorization: Bearer <token>'

Idempotent submission pipeline: (1) generate XML from the persisted invoice (cached in R2/S3); (2) XAdES-EPES sign with the tenant's .p12 certificate; (3) obtain an OAuth token from ATV IdP (auto-refreshed); (4) POST to ATV /recepcion. The response is the ATV ack — Hacienda processing is asynchronous; poll GET /v1/hacienda/status/:clave or wait for the webhook callback. When Hacienda (ATV or its IdP) does not answer — unreachable, timeout, 5xx, 408, 429 — the request fails with 502 and the document stays signed with its number: retry with backoff, or let the background sweep deliver it. When Hacienda REFUSES the stored ATV credentials the request fails with 424 TOKEN_REQUEST_FAILED: the document also stays signed, the credentials are marked as refused (no further login attempts with them), and it goes out on its own once they are updated. On 422 ATV_REJECTED the document was permanently rejected (see haciendaDetailMessage on the invoice).

invoiceId
required
string
Example
01a00c73-5c07-7bb5-8b9e-d20f16537e42

Invoice UUID

ATV ack — Hacienda received the document (indEstado: recibido); its verdict comes later. The response carries no invoice id nor consecutivo: read them from the invoice, or call POST /v1/invoices/:id/sign first.

Media typeapplication/json
object
clave
required

50-digit Hacienda key of the document.

string
>= 50 characters <= 50 characters
fecha
required

The emission instant the document declares (<FechaEmision>).

string format: date-time
indEstado
required

Hacienda's state. A submit answers recibido (received, not yet judged); the verdict (aceptado / rechazado) arrives later — read it from the invoice, the status endpoint or the webhooks.

string
Allowed values: recibido procesando aceptado rechazado error
respuestaXml

Hacienda's response XML (MensajeHacienda), base64-encoded. Present once Hacienda has judged the document.

string
detalleMensaje

On a submit, the HTTP status of Hacienda's acknowledgement (HTTP 202). Once Hacienda has judged the document, its DetalleMensaje — the reason of a rejection.

string
Example
{
"indEstado": "recibido"
}

Missing or invalid JWT / API key

Invoice not found or belongs to a different tenant.

Hacienda refused: the stored ATV credentials (TOKEN_REQUEST_FAILED) or the request (ATV_NETWORK_ERROR with messageKey errors.ATV_REQUEST_REJECTED, reason in the message).

Hacienda did not answer (ATV_NETWORK_ERROR, TOKEN_REQUEST_FAILED with messageKey errors.HACIENDA_IDP_UNAVAILABLE). The document stays signed; retry with backoff.