TF Fiscal

Core APIs

Received Documents & DistDFe

8 endpoints

Recipient Manifestation allows the NF-e recipient to formally position themselves regarding an invoice issued against their CNPJ. There are 4 event types defined by the tax authority, each with its own legal meaning.

Event Types

CodeNameMeaningJustification
210210 Operation Awareness The recipient acknowledges the NF-e exists but has neither confirmed nor rejected it yet. Usually the first event, and a requirement to download the full XML via DistDFe. Not required
210200 Operation Confirmation The recipient confirms the operation took place and the goods/services were received. Final event, proves receipt. Not required
210220 Operation Unawareness The recipient declares they do NOT recognize the operation (suspected fraud, misuse of CNPJ, etc.). Required (15-255 chars)
210240 Operation Not Performed The recipient acknowledges the operation but declares it did NOT take place (return, refusal of delivery, etc.). Required (15-255 chars)
Sequence rule: After sending Awareness (210210), you may send Confirmation (210200) OR Unawareness (210220) OR Not Performed (210240). Confirmation/Unawareness/Not Performed are final states — they cannot be overwritten.
Attention: The CNPJ sent in the cnpj field must be the recipient of the NF-e (the one manifesting) and must be registered in the system bound to the token in use. Otherwise tax authority returns the rejection "The event author differs from the NF-e recipient".

Return cStat Codes

cStatMeaning
135✅ Event successfully registered
573✅ Event duplicity — already registered (treated as success)
236❌ Invalid access key
491❌ Manifestation already registered — cannot overwrite final state
596❌ Recipient CNPJ differs from informed one
656❌ Improper consumption (rate limit)
POST/api/invoice/manifest

Send recipient manifestation event

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
chavestringYesNF-e access key — 44 digits
cnpjstringYesRecipient CNPJ (the one manifesting) — 14 digits, unformatted. Must be registered in the system
tipo_eventointYesEvent code: 210200, 210210, 210220 or 210240
justificativastringConditionalRequired for 210220 and 210240. Must be 15–255 characters. Ignored for 210200 and 210210
Sequence (nSeqEvento): calculated automatically. For the same combination (cnpj + chave + tipo_evento) it increments on each call — so duplicates return cStat: 573 and are saved without error.

Response Fields

FieldTypeDescription
idstringInternal ObjectId of the manifestation record (used in /get_xml)
chavestringAccess key of the manifested NF-e
cnpjstringRecipient CNPJ that manifested
tipo_eventointEvent code sent (210200/210210/210220/210240)
desc_eventostringEvent textual description (tax authority original wording)
nProtstringtax authority protocol number — event receipt
cStatinttax authority status code. 135 = registered, 573 = duplicity (also accepted)
xMotivostringtax authority descriptive return message
nSeqEventointEvent sequence assigned automatically
xml_urlstringPublic URL of the procEvento XML (signed and protocoled) stored in OSS
POST/api/invoice/manifest/list

List manifestations

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
cnpjstringNoFilter by recipient CNPJ. If omitted, lists across all of the user's CNPJs
chavestringNoFilter by a specific NF-e access key (44 digits)
start_create_timestring/longNoStart date. Accepts: "dd/MM/yyyy", "yyyy-MM-dd", "dd/MM/yyyy HH:mm:ss" or Unix timestamp in seconds. Considers 00:00:00 UTC if date-only
end_create_timestring/longNoEnd date. Same formats. If date-only, considers 23:59:59.999 UTC
pageintNoPage number (default 1)
page_sizeintNoItems per page (default 20, max 100)

Response Fields

FieldTypeDescription
totalintTotal records matching the filters (regardless of pagination)
pageintCurrent page returned
page_sizeintPage size returned
list[].idstringInternal ObjectId of the record
list[].chavestringAccess key of the manifested NF-e
list[].cnpjstringRecipient CNPJ that manifested
list[].tipo_eventointEvent code (210200/210210/210220/210240)
list[].desc_eventostringEvent textual description
list[].justificativastringSent justification (filled only for 210220/210240)
list[].nProtstringtax authority protocol number for the event
list[].nSeqEventointEvent sequence
list[].cStatinttax authority status code
list[].xMotivostringtax authority descriptive return message
list[].xml_urlstringPublic URL of the procEvento XML in OSS
list[].createstringUTC creation timestamp (format yyyy-MM-dd HH:mm:ss)
Ordering: records are returned from newest to oldest (by create descending).
POST/api/invoice/manifest/get_xml

Get manifestation XML

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
idstringYesManifestation ObjectId — returned by /manifest or /manifest/list

Common Errors

MessageCause
id inválidoValue is not a valid ObjectId
manifestação não encontradaObjectId exists but does not belong to the token's user, or was deleted

Allows querying and downloading NFes and events destined to your CNPJ via the NFeDistribuicaoDFe service from the tax authority (National Environment). Capture is incremental by NSU (Unique Sequential Number) — each call only downloads what has not been captured yet.

Returned Document Types

doc_typeWhat it isContent
resNFe NFe summary Basic metadata (key, value, issuer, status). Comes BEFORE the Awareness event is sent — does not contain products/taxes
procNFe Full authorized NFe Complete NF-e XML (with products, taxes, transport, etc.). Only available AFTER the recipient sends Awareness (210210) for the key
resEvento Event summary Event metadata (key, type, sequence, reason)
procEvento Full event Complete event XML (CC-e, cancellation, manifestations from other recipients on your invoices)
Recommended flow:
  1. Call /received/sync — downloads all new documents
  2. List with /received/list filtering by doc_type: "resNFe" to see invoices without Awareness
  3. For each key of interest, call /invoice/manifest with tipo_evento: 210210
  4. Call /received/sync again — now tax authority returns the procNFe (full XML) of the manifested keys
  5. Use /received/get_xml to fetch the XML URL and process
tax authority rate limit: tax authority allows at most 1 DistDFe call per hour per CNPJ. Exceeding this returns cStat: 656 (Improper Consumption). In homologation the rule is more permissive.

DistDFe Return cStat Codes

cStatMeaning
137✅ No documents found (normal end of loop)
138✅ Documents found — loop continues
656❌ Improper consumption — wait 1h and retry
252❌ Environment differs from informed (production vs homologation)
280❌ Certificate expired or invalid
POST/api/invoice/received/sync

Sync received documents

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
cnpjstringYesRecipient company CNPJ — 14 digits, unformatted. Must be registered in the system bound to the token
max_iterationsintNoMaximum number of the tax authority calls per execution. Each call downloads up to 50 documents. Default 50 (≈2,500 docs), max 200
How it works:
  • Reads the last ultNSU persisted for that (uid + cnpj)
  • Loops calling tax authority until cStat ≠ 138 or max_iterations is reached
  • Decompresses the returned XMLs (gzip)
  • Persists each document in w_invoice_received with XML uploaded to OSS
  • Updates ultNSU and maxNSU in w_invoice_received_sync
  • Deduplicates by (uid + cnpj + nsu) — repeated calls don't duplicate

Response Fields

FieldTypeDescription
cnpjstringRecipient CNPJ queried
ufstringRecipient state used in the query
initial_nsulongStarting NSU — the last one processed before this run
ult_nsulongNew last NSU after the sync
max_nsulongLargest NSU available in the national environment (AN) at the time of the query
pendinglongDocuments still pending (max_nsu - ult_nsu). If > 0, call /sync again to download the rest
iterationsintHow many tax authority calls were made in this run
last_cstatintLast cStat returned by the tax authority. 137 is normal end, 656 is rate limit
last_motivostringtax authority descriptive return message for the last call
stats.resNFeintNumber of NFe summaries downloaded in this run
stats.procNFeintNumber of full NFes downloaded
stats.resEventointNumber of event summaries downloaded
stats.procEventointNumber of full events downloaded
stats.skippedintDocuments skipped (duplicates or isolated parse error)
Initial volume: companies that have never synced may have hundreds to thousands of historical documents. The first run may take longer and be interrupted by max_iterations. Check pending in the response — if > 0, call again (respecting the rate limit).
POST/api/invoice/received/list

List received documents

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
cnpjstringNoFilter by recipient CNPJ (your CNPJ). If omitted, lists across all of the user's
doc_typestringNoFilter by document type: resNFe, procNFe, resEvento or procEvento
chavestringNoFilter by access key (44 digits)
emitente_cnpjstringNoFilter by NF-e issuer CNPJ (supplier)
start_create_timestring/longNoStart date. Accepts "dd/MM/yyyy", ISO or Unix timestamp
end_create_timestring/longNoEnd date. Same formats
pageintNoPage number (default 1)
page_sizeintNoItems per page (default 20, max 100)

Response Fields

FieldTypeDescription
totalintTotal records matching the filters
pageintCurrent page
page_sizeintPage size
list[].idstringInternal ObjectId (use in /received/get_xml)
list[].nsulongNSU assigned by the tax authority to this document
list[].doc_typestringDocument type: resNFe, procNFe, resEvento, procEvento
list[].schemastringDocument schema (e.g. resNFe_v1.01.xsd)
list[].chavestringNF-e access key (44 digits)
list[].cnpj_destinatariostringRecipient CNPJ (your CNPJ)
list[].emitente_cnpjstringNF-e issuer CNPJ (supplier)
list[].emitente_nomestringIssuer company name
list[].valordecimalNF-e total value (vNF)
list[].dh_emistringNF-e issuance date/time
list[].serieintNF-e series (filled only for procNFe)
list[].numberlongNF-e number (filled only for procNFe)
list[].tp_nfintOperation type: 0=Inbound, 1=Outbound (from the issuer's perspective)
list[].c_sit_nfeintNF-e status (filled in resNFe): 1=Authorized, 2=Denied, 3=Canceled
list[].tp_eventointEvent code (filled in resEvento/procEvento). E.g. 110110=CC-e, 110111=Cancellation, 210210=Awareness
list[].desc_eventostringEvent textual description
list[].n_seq_eventointEvent sequence
list[].dh_eventostringEvent date/time (events only)
list[].xml_urlstringPublic URL of the document XML in OSS
list[].createstringUTC capture timestamp
Ordering: records are returned by NSU descending (most recent first).
POST/api/invoice/received/get_xml

Get received document XML

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
idstringYesDocument ObjectId — returned by /received/list
About the returned XML:
  • resNFe — XML is the summary only, does NOT contain products/taxes. Use for auditing/triage before sending Awareness
  • procNFe — Full signed XML, equivalent to the one generated at issuance. Ready to import into the client's ERP
  • procEvento — Full event XML with signature and protocol

Common Errors

MessageCause
id inválidoValue is not a valid ObjectId
documento recebido não encontradoObjectId exists but does not belong to the token's user
POST/api/invoice/received/get_prod

Get products from received NF-e

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
chavestringYes44-digit NF-e access key (model 55). The check digit is validated before calling SEFAZ
ciencia_notaboolNoDefaults to false. With true, if SEFAZ has not released the full XML yet, the endpoint registers the Acknowledgement of Operation (event 210210) with the company certificate and queries again
ambienteintNo1 production (default) or 2 staging

Response Fields

FieldTypeDescription
chavestringAccess key that was queried
total_itensnumberNumber of items in the invoice
itensarrayOne object per invoice item (det)
itens[].nItemnumberItem number within the invoice
itens[].prodobjectThe prod group of the NF-e layout, keeping the original tag names. Quantities and amounts come as numbers; codes such as cProd, NCM and cEAN come as text, preserving leading zeros. Tags that repeat in the layout (NVE, DI, detExport, rastro) always come as a list
itens[].infAdProdstringAdditional item information, when present
How SEFAZ delivers the XML
  • The receiving company comes from the token; do not send a CNPJ in the body.
  • The query uses document distribution (DistDFe) at the National Environment, with the company’s own certificate.
  • Without a manifestation, SEFAZ returns only the summary, with no items. Use ciencia_nota: true to release the full XML.
  • The Acknowledgement only states awareness of the invoice: it neither confirms receipt of the goods nor prevents the issuer from cancelling it.
  • A freshly authorized invoice may take hours until the National Environment distributes it. Until then the response is invoice not found.
  • An invoice issued by the company itself is not distributed to it; query with the receiving company’s token.
  • The query stores nothing. Only the Acknowledgement, when triggered, registers an event at SEFAZ.

Common Errors

MessageCause
Chave inserida inválida / 发票密钥无效Key without 44 digits, with a non-numeric character, or with a wrong check digit
Apenas NF-e modelo 55 pode ser consultada pela chaveThe key belongs to an NFC-e (model 65), which SEFAZ does not distribute
empresa não encontrada para este tokenThe token is not linked to any registered company
empresa não possui certificado configuradoThe company has no valid A1 certificate on file
nenhum documento localizado para esta chave e este CNPJ...The National Environment has not distributed the invoice yet, the environment is different, or the company is not the recipient
esta nota foi emitida por este CNPJ e a SEFAZ não a distribui ao próprio emitenteQuerying an outgoing invoice with the issuer’s own token (SEFAZ 641)
SEFAZ devolveu apenas o resumo da nota (sem itens)...Invoice still without Acknowledgement; call with ciencia_nota=true
consumo indevido: a SEFAZ bloqueou consultas repetidasSEFAZ per-CNPJ limit; wait before retrying
When the ciencia_nota flag triggers the event or finds one already registered, the error response carries data.ciencia with the event outcome. Every other error returns only success and message.
POST/api/invoice/received/get_sync_status

Get sync status

Required headers

HeaderTypeDescription
tokenstringCompany token
signstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
cnpjstringYesRecipient company CNPJ — 14 digits, unformatted

Response Fields

FieldTypeDescription
cnpjstringCNPJ queried
ufstringRecipient state used in the last sync (absent if never synced)
ult_nsulongLast NSU processed. 0 = never synced
max_nsulongLargest NSU available in the tax authority at the last sync
pendinglongPending documents (max_nsu - ult_nsu). If > 0, there are new documents in the tax authority
last_syncstringUTC date/time of the last successful sync. null if never synced
Typical use: call this endpoint before /received/sync to decide whether to call tax authority. This endpoint does not consume the tax authority rate limit — it only reads local MongoDB state.