Documentation › First steps
Integration rules
The twelve rules that prevent duplicate invoices, wrong retries and exceeded limits.
Twelve rules. Each one prevents a real integration problem.
- Send
Idempotency-KeyinPOST /v1/nfseandPOST /v1/lotes. It is not required, but without it a timeout followed by a retry can create a second invoice. See Idempotency. - When you repeat the same attempt, use the SAME
Idempotency-Key. Generate one per invoice, store it with the order and reuse it. A new key is a new invoice. - Send
referenciain every invoice (your order number, for example). It is unique per company and environment: a second invoice with the samereferenciais refused (409referencia_duplicada). This protection still applies after the 30 days theIdempotency-Keyis kept. - 202 is not an error. The invoice exists and is
transmitindo. Track it; do not issue again. - In production, prefer a webhook to repeated queries. Subscribe to
NFSE_AUTORIZADA,NFSE_REJEITADAandNFSE_FALHA_TRANSMISSAO. - If you query, do not query too often. The limit is 120 requests per
minute per key, and an invoice in
transmitindodoes not change every second. One query every 30 seconds per invoice is enough. - Money and tax rates go as text with a decimal point:
"1500.00","2". A JSON number is refused (tipo_invalido). - Code against
codigo, never againstmensagem. The message is for people and its text can change;codigois stable. - Store
X-Request-Id(orrequisicao_id) of every call that failed. With it you find the call in Integrações › Log da API (Integrations › API log). - Treat the cursor as an opaque value. Store it and send it back exactly as it came, without interpreting or building it. See Pagination and limits.
- Retry only what can succeed when repeated. Retry when the error has
retentavel: true, on 429, 5xx and timeout, always with the sameIdempotency-Key. Do not retry 400, 401, 403, 404, 409, 412 or 422 without fixing first. See the retry recipe. - On
falha_transmissao, readfalha.dps_enviadabefore issuing again. With"desconhecido", the invoice may have been issued: check in the Emissor Nacional first.