Your first document
Issue a document, get a signed comprobante, and wait for Hacienda's verdict.
Issuing a comprobante is a two-step flow: you create the document (Sello
builds, signs, and persists it synchronously, then enqueues only the Hacienda
submission — returning 201 right away) and then you wait for Hacienda's
terminal verdict, either by polling status or by receiving a webhook.
Before you start
You need two things:
- A sandbox emisor. Every new emisor starts in sandbox and files to Hacienda's pruebas environment until onboarding promotes it.
- A
testkey (get one). A test key can only act on a sandbox emisor, so with a test key nothing you do here files for real.
Use a sandbox emisor and a test key for this walkthrough. With a
live key on a promoted (production) emisor, the same call files a
real comprobante with Hacienda production — a binding tax document that
you cannot delete, only cancel with a nota de crédito.
There is one base URL, https://api.sello.cr; the emisor decides where the
document goes (see Environments).
1. Create the document
POST /v1/documents with the document body. Mutations require an
Idempotency-Key header (see Idempotency).
curl -X POST https://api.sello.cr/v1/documents \
-H "Authorization: Bearer $SELLO_API_KEY" \
-H "Sello-Version: 2026-06-15" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"tipo": "FE",
"emisor": { "…": "…" },
"receptor": { "nombre": "Cliente" },
"condicionVenta": "01",
"medioPago": ["01"],
"detalleServicio": [ { "…": "…" } ],
"resumenFactura": {
"totalVenta": "1000.00",
"totalImpuesto": "130.00",
"totalComprobante": "1130.00"
}
}'Sello validates the body, builds the v4.4 XML, allocates the consecutivo and
the 50-digit clave, signs the document, and persists it — all on the
request path. Only the Hacienda submission is enqueued for out-of-band delivery.
You get back 201 Created (a 200 OK on an idempotent replay), and the document
is already signed:
{
"clave": "50601...<50 digits>",
"numeroConsecutivo": "00100001010000000001",
"tipo": "FE",
"state": "signed",
"fechaEmision": "2026-06-15T10:00:00-06:00"
}The clave is your handle for everything that follows. Note that clave,
numeroConsecutivo, and fechaEmision are server-allocated — never send
them on create. The response can also include an advisory warnings[] array
(non-blocking findings such as an unknown CABYS code) — see
Issuing documents for the shape.
2. Wait for the verdict
A signed document is not yet accepted by Hacienda. The engine submits the
signed comprobante out of band and tracks it through the rest of the state machine
signed → submitted → accepted | rejected. Hacienda's own verdict lives in the
ind-estado field: procesando (still in flight) →
aceptado / rechazado / error (terminal).
Poll the status endpoint until ind-estado is terminal:
curl https://api.sello.cr/v1/documents/<clave> \
-H "Authorization: Bearer $SELLO_API_KEY"{
"clave": "50601...",
"fecha": "2026-06-15T10:00:00Z",
"ind-estado": "aceptado",
"respuesta-xml": "<base64 Hacienda response>"
}The easy way: the SDK waiter
The SDK does the create-then-poll dance for you, with backoff that honors a
server Retry-After:
import { isAcceptedIndEstado } from '@magiios/sdk';
const status = await sello.documents.createAndWait(
{ tipo: 'FE', /* … */ },
// The Idempotency-Key is required: derive it from the order, not the content.
{ idempotencyKey: `order-${order.id}:FE`, intervalMs: 2000, timeoutMs: 120_000 },
);
// The generated model exposes the hyphenated wire field ind-estado as indEstado.
if (isAcceptedIndEstado(status.indEstado)) {
console.log('Aceptado por Hacienda', status.clave);
} else {
console.warn('Terminal but not accepted:', status.indEstado);
}Both acceptance and rejection resolve (inspect ind-estado to branch); only
a timeout rejects. See Async issuance for the full
lifecycle, and Webhooks for the push alternative to
polling.