Two-phase emit
Submitting does everything in one call: allocate the fiscal number, sign the XML, and POST to Hacienda’s ATV — returning only after ATV’s recibido ack. That ties your response time (and success) to Hacienda’s health.
But the consecutivo and clave don’t depend on Hacienda accepting anything:
EmiteCR allocates them and signs locally, before any network call to ATV.
Two-phase emit exposes that seam:
| Phase | Endpoint | What happens | Depends on Hacienda |
|---|---|---|---|
| 1 — sign | POST /v1/invoices/:id/sign |
Allocate consecutivo + clave, generate + XAdES-sign the XML → status: signed |
No — fast and reliable |
| 2 — submit | POST /v1/hacienda/submit/:id, or EmiteCR in the background |
POST to ATV → submitted → verdict via webhooks / polling |
Yes |
Built for point of sale: the number prints on the customer’s receipt immediately, even while ATV is slow or down.
Sign, print, then submit
Section titled “Sign, print, then submit”curl -X POST "https://api.emite.cr/v1/invoices/$INVOICE_ID/sign" \ -H "x-api-key: $EMITECR_API_KEY"{ "invoiceId": "7c2a9b38-…", "consecutivo": "00100001040000004521", "clave": "50621102600310123456700100001040000004521100000001", "status": "signed", "submitEnqueued": false}Print the receipt, then submit — right away, or from a background job of yours:
curl -X POST "https://api.emite.cr/v1/hacienda/submit/$INVOICE_ID" \ -H "x-api-key: $EMITECR_API_KEY"If that call fails — or you never make it — EmiteCR sends the document itself: a
sweep picks up every document that has been signed for more than 15 minutes
and submits it. An allocated number always reaches Hacienda; “sign and hold” is
not a state a document can stay in.
That is also why both endpoints require the invoices:sign and
invoices:submit scopes: signing
already commits the document to Hacienda.
Let EmiteCR submit at once (?submit=async)
Section titled “Let EmiteCR submit at once (?submit=async)”POST /v1/invoices/:id/sign?submit=async signs and enqueues the submit in the
background right away (with retries), answering "submitEnqueued": true. It is
reserved to keys minted by a partner — anything else gets
403 ASYNC_SUBMIT_PARTNER_ONLY — because an async caller that doesn’t consume
webhooks would never learn the verdict. With your own company’s key, call
submit yourself after signing; the result is the same.
Guarantees
Section titled “Guarantees”- Idempotent — re-signing the same document returns the same number, and never enqueues a duplicate submit.
- Nothing signed is ever stranded — the sweep re-submits any
signeddocument stuck without a submit (crashed process, lost enqueue, long ATV outage). If a document still can’t be submitted after 24 hours (or fails with a permanent error like an expired certificate), it turnsstatus: errorand fires theinvoice.errorwebhook. - Quota is checked at signing — an over-quota company fails before a number is handed out, and an already-signed document is never re-checked: a number you printed is always emittable.
situacionis immutable after signing — it’s embedded in the clave (digit 42). Decide it at sign time (see Situación & contingency).
Voucher content before acceptance
Section titled “Voucher content before acceptance”Hacienda’s verdict is asynchronous in EVERY mode (even the plain submit returns at recibido, not aceptado). Print on the receipt:
- the clave (ideally as a QR pointing at Hacienda’s verification page),
- the consecutivo (human-readable number),
- a legend such as “Comprobante electrónico en proceso de validación ante el Ministerio de Hacienda”.
Rejections after printing are rare — totals are hard-validated before the
number is allocated — and are handled by issuing a corrected document with an
attempt suffix (externalReference: "<ticket>:2").
Which mode should I use?
Section titled “Which mode should I use?”| You are… | Use |
|---|---|
| A point of sale that prints receipts | create → sign → print → submit in the background, plus webhooks or polling for the verdict |
| A backend that can wait 1–3 s for Hacienda’s ack | create → submit |
| A partner product | create → sign ?submit=async + webhooks |