Skip to content

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.

An API key acts on behalf of a company that already exists in EmiteCR. In the web app (app.emite.cr):

  1. Create the account and the company, with its cédula.
  2. 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.
  3. Company → Certificate: upload the sandbox .p12 with 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.

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.

Ventana de terminal
export EMITECR_API_KEY="ec_test_…"
export BASE="https://api.emite.cr/v1"

Check that it works:

Ventana de terminal
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.

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:

Ventana de terminal
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
}
]
}'
  • code is the line’s CAByS code — 6340001000100 is Café caliente, vendido en restaurantes, bares y establecimientos similares. Find codes with GET /v1/cabys/search?q=café and the IVA option for one with GET /v1/cabys/:code/suggested-iva.
  • unitPrice is before tax. You send each line’s subtotal, tax monto and total; the server recomputes them and refuses any difference over ±0.005 with 422 INVOICE_TOTALS_MISMATCH. The rules are in Create an invoice.
  • paymentMethods: 01 efectivo, 02 tarjeta, 04 transferencia, 06 SINPE Móvil.
  • externalReference is your own id for the sale, and the API never accepts it twice. Together with Idempotency-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:

Ventana de terminal
export INVOICE_ID="…" # the "id" of the response
Ventana de terminal
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.

Ventana de terminal
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.

EmiteCR asks Hacienda for the verdict on its own. Read the document:

Ventana de terminal
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.

Ventana de terminal
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.

When the integration works in sandbox:

  1. A plan in force. Production keys can only read while the company has no plan (402 SUBSCRIPTION_INACTIVE).
  2. Production credentials in Company → Certificate: the production .p12 and the production ATV username and password.
  3. 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.
  4. A production key (ec_live_…) with the same scopes, deployed in place of the sandbox one. Everything else — URLs, payloads, flow — stays the same.
  • 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.code means and what to do.