Skip to content

Status & polling

Hacienda’s ATV processes documents asynchronously. After you submit, the document goes recibido → procesando → aceptado | rechazado over seconds to minutes. This guide covers how to learn the terminal state. If you’d rather be pushed than poll, use webhooks.

Field Meaning Values
status API lifecycle draft → signed → submitted → accepted | rejected | error
haciendaStatus ATV-reported state recibido, procesando, aceptado, rechazado, error, null
haciendaDetailMessage ATV reason on terminal state free text — your primary rejection-debugging signal

Read them via GET /v1/invoices/:id:

{
"id": "…",
"clave": "506…",
"status": "accepted",
"haciendaStatus": "aceptado",
"haciendaDetailMessage": "Comprobante recibido satisfactoriamente"
}

You usually don’t need to poll ATV aggressively — the API runs a background hacienda.poll job after every submit, with exponential backoff, that updates status / haciendaStatus / haciendaDetailMessage when ATV resolves (and emits the webhook). So a client can just call GET /v1/invoices/:id on a relaxed cadence (~30s) and trust the poller to catch the terminal state.

Two endpoints exist:

Ventana de terminal
GET /v1/invoices/:id # read from DB (recommended)
GET /v1/hacienda/status/:clave # force a fresh synchronous ATV poll

Prefer the first unless you specifically need to bypass caching. Either way, a verdict is recorded once: whichever check sees it first updates the document and sends its webhook and email, and calling GET /v1/hacienda/status/:clave again afterwards only reads Hacienda’s answer — it announces nothing a second time.

Stop polling when:

Condition Meaning
status === "accepted" Success — final
status === "rejected" Permanent rejection — read haciendaDetailMessage
status === "error" Pipeline error — see errorReason

errorReason (when status === "error"): POLL_TIMEOUT_24H, SUBMIT_TIMEOUT_24H, ATV_REJECTION, XML_INVALID, CLAVE_DUPLICATED, ATV_AUTH_REVOKED, CERTIFICATE_INVALID, ENCRYPTION_FAILED, UNKNOWN_FINAL. The two timeouts really mean 24 hours: a Hacienda outage shorter than that leaves the document submitted (or signed) and it resolves by itself.

async function waitForFinalStatus(invoiceId, { maxAttempts = 30, baseDelayMs = 5_000, maxDelayMs = 120_000 } = {}) {
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const inv = await fetchInvoice(invoiceId);
if (inv.status === 'accepted') return { ok: true, invoice: inv };
if (inv.status === 'rejected') return { ok: false, reason: 'rejected', message: inv.haciendaDetailMessage };
if (inv.status === 'error') return { ok: false, reason: inv.errorReason };
await sleep(Math.min(maxDelayMs, baseDelayMs * 2 ** Math.min(attempt, 5)) + Math.random() * 500);
}
return { ok: false, reason: 'POLL_BUDGET_EXHAUSTED' };
}

For systems that don’t want to block per-request: submit, store the id keyed by your business event, and run a scheduled job that fetches open ones via GET /v1/invoices and mirrors the terminal states into your domain.

Once terminal, all three XML artifacts are available:

Ventana de terminal
GET /v1/invoices/:id/xml?type=hacienda-response
type What
unsigned XML built from the persisted invoice, pre-signing
signed The canonical signed XML submitted to ATV
hacienda-response ATV’s ack XML (only after a terminal state)

signed is the default when type is omitted. unsigned and signed exist once the document is signed; before that the endpoint answers 404.

The PDF:

Ventana de terminal
GET /v1/invoices/:id/pdf?locale=es # application/pdf — rendered invoice, logo, QR

Once the document is signed, the PDF shows exactly what its signed XML declares; for a draft it is a preview. Add disposition=inline to either download to open it in the browser instead of saving it. The PDF needs the invoices:read scope, and the XML invoices:export.