- get a sandbox API key from the developer console;
- register a webhook endpoint;
- create and send an invoice;
- follow its status, by polling or by webhook;
- verify the webhook signature.
https://api.cufea.com/openapi.json.
Before you start
You need nothing installed butcurl. The commands below use these two variables:
1. Get a sandbox key
Open the developer console at app.cufea.com/signup and sign up with an email and a password. You get a sandbox tenant, and the console asks you to verify your email before anything else: open the link it emails you, then log in again. Once verified, choose Create your sandbox API key on the dashboard to get a firstcufea_sandbox_ key. The key is shown once: copy it into CUFEA_KEY now. More keys can
be issued, and revoked, on the console’s Keys page.
Check it. /v1/tenant answers for any valid key:
401; every error is application/problem+json:
SBX); GET /v1/tenant/configuration shows "ready_to_invoice":true.
2. Register a webhook endpoint
Webhooks tell you when the DIAN answered, so you do not have to poll. The endpoint must be anhttps URL on a public host name: localhost and private addresses are refused. To receive
on your machine, expose it through an HTTPS tunnel of your choice.
event_types subscribes to every type: invoice.accepted, invoice.rejected,
note.accepted, note.rejected and event.registered. secret is shown once; keep it
where your receiver can read it, for step 5. The console’s Webhooks page does the same and
lists the latest deliveries.
3. Create and send an invoice
One request creates the invoice, signs it, stores it and, with"send": true, queues it for the
DIAN. This one is a cash sale of one service with 19% IVA to a company customer:
201 Created with a Location: /v1/invoices/SBX1 header:
document_idis the series and the number:SBX1for a new tenant’s first invoice.totals,taxes,withholdings,linesandqrare what the signed XML says, read from it: print your receipt from them.qr.contentis the value to encode in the printed QR.paymentslists one entry per means of payment, in order: a sale paid with cash and a card sends two (see Payments).xml_base64is the signed UBL XML, yours to keep.send: queuedmeans a worker will send it; the state staysprepareduntil then.Idempotency-Keymakes retries safe. If the answer is lost, repeat the exact request: you get the stored answer (withIdempotent-Replayed: true) and no second number is taken. Reusing a key with a different body answers422(idempotency_key_reused).GET /v1/documents?kind=invoice&reference=ORDER-1001also tells you whether an invoice with yourreferenceexists.
Line taxes: taxed, exempt and excluded
Each line lists its taxes. A retail catalog usually needs these five:
An exempt item is IVA at 0%: the XML informs IVA with
0.00, and its value counts in the
taxable base (TaxExclusiveAmount). An excluded item takes no scheme and no rate: the XML
informs no IVA for that line (Anexo 1.9, FAX01 and FAX05) and its value stays out of the
taxable base (FAU04). An excluded entry may sit next to another tax such as INC, but not next
to an IVA entry, and it never carries scheme or percent; those requests answer 422.
A line with an empty taxes list produces the same XML as an excluded one.
Customers without full fiscal data
Only the identification and the name of an identified buyer are required. Withoutfiscal_responsibilities the buyer gets ["R-99-PN"], without tax_scheme it gets ZZ,
and without address the XML leaves out the buyer’s PhysicalLocation and
RegistrationAddress (both optional in the Anexo 1.9, FAK07 and FAK28). Send the address
when the sale happens outside your premises: FAK07 requires it then.
"kind": "final_consumer" and nothing else (an email and an
address are optional). Cufea fills the consumidor final party the Anexo prescribes:
natural person, id type 13, id 222222222222, name consumidor final, R-99-PN and ZZ.
Line discounts
A line takes an optional discount, as a percentage (discount_rate) or an amount
(discount_amount): decimal strings with at most two decimals, one or the other, never both
(422 validation_error). The amount cannot exceed quantity x unit_price and the rate
cannot exceed 100 (422 invoice_invalid). The line value is quantity x unit_price minus
the discount, and its taxes apply to that discounted value. The XML carries the discount as a
line AllowanceCharge (Anexo 1.9, FBE01-FBE09); AllowanceTotalAmount stays 0.00, since it
only sums document-level discounts. Note lines accept the same fields.
180000.00 with 34200.00 of IVA; the mouse line is worth
45000.00 with 8550.00 of IVA.
Without "send": true, send it later with POST /v1/invoices/SBX1/send, which answers 202.
A body that is not valid answers 422 with the offending fields and never echoes your values:
4. Follow the status
Read the invoice back untilstate is final (accepted or rejected). The sandbox usually
answers within a few seconds:
dian_status_code 00 is the DIAN’s “processed correctly”, and qr.url now links the
document in the DIAN catalog.
delivery is the email of the invoice to its buyer. In production Cufea sends it after the
DIAN accepts the invoice; the sandbox never emails anyone, so here it is skipped. Download
the PDF with GET /v1/invoices/SBX1/pdf, or the email’s subject and ZIP with
GET /v1/invoices/SBX1/email-content.
A rejection lists the DIAN rules in dian_errors. Or let the webhook tell you: when the
state becomes final your endpoint receives
2xx within 10 seconds. No answer, 408, 429 or 5xx is retried after 1
min, 5 min, 30 min, 2 h and 6 h; any other status fails the delivery at once. A delivery can
arrive more than once, so deduplicate on the body’s id.
5. Verify the webhook signature
X-Cufea-Signature is t=<unix seconds>,v1=<hex>. t is when this attempt was sent (a retry
is signed again with a fresh t), and v1 is the hex HMAC-SHA256 of t, a . and the raw
request body, keyed with the endpoint’s secret. Check it before trusting the body:
- compute it over the bytes exactly as received, before any JSON parsing (re-serializing the JSON changes the bytes, and the signature no longer matches);
- compare in constant time;
- reject a
tmore than 300 seconds away from your clock, in either direction: a captured request replayed later then fails; - accept the request when any
v1=entry matches (several appear while a secret is rotated), and ignore keys you do not know.
await request.body() in FastAPI or Starlette,
request.get_data() in Flask, express.raw({ type: "application/json" }) in Express. Answer
401 when verify is false.
Next
- The guides cover what a production client must decide: customers and DANE
codes, series, idempotency after 24
hours, rate limits, webhook ordering,
closeddocuments, payments and rounding. - The TypeScript SDK,
@cufea/sdk, wraps these steps: typed requests, automaticIdempotency-Keys, typed errors andwebhooks.verify. - The MCP server,
@cufea/mcp, gives AI agents (Claude Code, Cursor, Codex) these steps as tools, against the sandbox. GET /v1/invoices/SBX1/xmldownloads the signed XML, andPOST /v1/notesissues a credit or debit note on an accepted invoice. RADIAN events (POST /v1/invoices/{id}/events) need the buyer to be the issuer itself.- From test to production goes from the sandbox to the DIAN test environment with your own certificate, and then to production.
- Every request carries an
X-Request-IDresponse header, also in each error’srequest_id: quote it when something looks wrong (see Errors).