Quickstart: your first invoice
This guide takes your system from nothing to a document accepted by Hacienda — first in sandbox, where everything is free and nothing has fiscal value. Every step is a plain HTTP call, so any language works.
1. Prepare the company in the web app
Section titled “1. Prepare the company in the web app”An API key acts on behalf of a company that already exists in EmiteCR. In the web app (app.emite.cr):
- Create the account and the company, with its cédula.
- Company → Tax details: the company’s address — provincia, cantón and distrito, without which no document can be issued — and its economic activities registered at Hacienda.
- Company → Certificate: upload the sandbox
.p12with its PIN, and the username and password of Hacienda’s ATV for the test environment. EmiteCR checks the certificate against the company’s cédula and the credentials against Hacienda before saving them.
A new company already has a branch (001) and a terminal (00001); every
document uses them unless you choose others.
2. Create a sandbox API key
Section titled “2. Create a sandbox API key”In Developers → API keys, press Create API key, choose Sandbox and keep the Issue documents preset — its five scopes are what issuing and downloading the XML take. Copy the key: it is shown only once. Details in Authentication.
export EMITECR_API_KEY="ec_test_…"export BASE="https://api.emite.cr/v1"Check that it works:
curl "$BASE/invoices?pageSize=1" -H "x-api-key: $EMITECR_API_KEY"# 200 → {"items":[],"total":0,"page":1,"pageSize":1}A 401 means the key was mistyped, or it was revoked or expired.
3. Create the document
Section titled “3. Create the document”A sale becomes a draft first. This one is a Tiquete Electrónico (04) —
what a shop gives a customer who doesn’t ask for a factura, so it needs no
receiver — for two coffees at ₡1 500 each plus 13 % IVA:
curl -X POST "$BASE/invoices" \ -H "x-api-key: $EMITECR_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: sale-0001" \ -d '{ "docType": "04", "currency": "CRC", "saleCondition": "01", "paymentMethods": [{ "type": "01" }], "externalReference": "sale-0001", "lines": [ { "lineNumber": 1, "code": "6340001000100", "description": "Café caliente", "quantity": 2, "unitOfMeasure": "Unid", "unitPrice": 1500, "subtotal": 3000, "taxes": [{ "codigo": "01", "codigoTarifa": "08", "tarifa": 13, "monto": 390 }], "total": 3390 } ] }'codeis the line’s CAByS code —6340001000100is Café caliente, vendido en restaurantes, bares y establecimientos similares. Find codes withGET /v1/cabys/search?q=caféand the IVA option for one withGET /v1/cabys/:code/suggested-iva.unitPriceis before tax. You send each line’ssubtotal, taxmontoandtotal; the server recomputes them and refuses any difference over ±0.005 with422 INVOICE_TOTALS_MISMATCH. The rules are in Create an invoice.paymentMethods:01efectivo,02tarjeta,04transferencia,06SINPE Móvil.externalReferenceis your own id for the sale, and the API never accepts it twice. Together withIdempotency-Key, it makes retrying safe — see Idempotency & retries.
The answer is 201 with the draft: "status": "draft", with clave and
consecutivo still null. Keep its id:
export INVOICE_ID="…" # the "id" of the response4. Sign it — the fiscal number, at once
Section titled “4. Sign it — the fiscal number, at once”curl -X POST "$BASE/invoices/$INVOICE_ID/sign" -H "x-api-key: $EMITECR_API_KEY"{ "invoiceId": "…", "consecutivo": "00100001040000000001", "clave": "50621102600310123456700100001040000000001100000001", "status": "signed", "submitEnqueued": false}Signing allocates the consecutivo and the 50-digit clave and signs the XML with the company’s certificate, without waiting for Hacienda — so a point of sale can print them on the receipt right away. Calling it again returns the same number.
5. Send it to Hacienda
Section titled “5. Send it to Hacienda”curl -X POST "$BASE/hacienda/submit/$INVOICE_ID" -H "x-api-key: $EMITECR_API_KEY"{ "clave": "50621102600310123456700100001040000000001100000001", "fecha": "2026-10-21T15:15:00.000Z", "indEstado": "recibido", "detalleMensaje": "HTTP 202"}recibido means Hacienda received the document; its verdict comes later.
You may skip step 4 and call submit on the draft directly — it signs first. A
signed document that is never submitted is sent by EmiteCR itself within half
an hour: an allocated number always reaches Hacienda.
6. Read the verdict
Section titled “6. Read the verdict”EmiteCR asks Hacienda for the verdict on its own. Read the document:
curl "$BASE/invoices/$INVOICE_ID" -H "x-api-key: $EMITECR_API_KEY"status goes from submitted to accepted — or rejected, with
Hacienda’s reason in haciendaDetailMessage. It usually takes seconds to a
couple of minutes. Poll every 30 seconds or so, or let EmiteCR push it to you
with webhooks. The details are in
Status & polling.
7. Download the PDF and the XML
Section titled “7. Download the PDF and the XML”curl -o tiquete.pdf "$BASE/invoices/$INVOICE_ID/pdf" -H "x-api-key: $EMITECR_API_KEY"curl -o tiquete.xml "$BASE/invoices/$INVOICE_ID/xml" -H "x-api-key: $EMITECR_API_KEY"The XML is the signed document; ?type=hacienda-response returns Hacienda’s
answer once it has one. A Factura Electrónica with the receiver’s email is also
emailed to the customer when Hacienda accepts it (PDF, XML and Hacienda’s
answer), unless the company turned that off in Settings → Notifications.
8. Go to production
Section titled “8. Go to production”When the integration works in sandbox:
- A plan in force. Production keys can only read while the company has no
plan (
402 SUBSCRIPTION_INACTIVE). - Production credentials in Company → Certificate: the production
.p12and the production ATV username and password. - The numbering, if the company is moving from another invoicing system: set where its consecutivos continue in Company → Numbering, so the first number does not repeat one Hacienda already has. See Consecutivo sequences.
- A production key (
ec_live_…) with the same scopes, deployed in place of the sandbox one. Everything else — URLs, payloads, flow — stays the same.
Next steps
Section titled “Next steps”- Create an invoice — facturas with a receiver, discounts, exoneraciones, other currencies.
- Two-phase emit — print the number before Hacienda answers.
- Webhooks — get the verdict pushed instead of polling.
- Error codes — what each
error.codemeans and what to do.