TF Fiscal

Received Documents & DistDFe

POST/api/invoice/received/sync

Sync received documents

Required headers

tokenstringstringCompany token
signstringstringMD5 signature: MD5(token + path + body + timestamp)
timestampstringstringUnix timestamp in seconds (5-minute window)

Fields

FieldTypeRequiredDescription
cnpjstringYesRecipient company CNPJ — 14 digits, unformatted. Must be a company registered under 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 ultNSU saved by the company's previous synchronization
  • Loops calling tax authority until cStat ≠ 138 or max_iterations is reached
  • Decompresses the returned XMLs (gzip)
  • Saves each document and stores its XML for download through /received/get_xml
  • Updates the synchronization progress (ultNSU and maxNSU)
  • Deduplicates by company and NSU — repeated calls do not save duplicates
  • Synchronization always runs in the production environment; the request does not accept ambiente

Response fields

cnpjstringstringRecipient CNPJ queried
ufstringstringRecipient state used in the query
initial_nsulonglongStarting NSU — the last one processed before this run
ult_nsulonglongNew last NSU after the sync
max_nsulonglongLargest NSU available in the national environment (AN) at the time of the query
pendinglonglongDocuments still pending (max_nsu - ult_nsu).
iterationsintintHow many tax authority calls were made in this run
last_cstatintintLast cStat returned by the tax authority.
last_motivostringstringtax authority descriptive return message for the last call
statsobjectobject
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).
Interpreting the result: when the tax authority returns 656 or another error code, this endpoint still returns success: true; the reason is in last_cstat and last_motivo. success: false is used only when the request itself is invalid (see the table below).

Common errors

MessageCause
Informe o cnpj / 请传入cnpjcnpj was not sent
empresa com CNPJ ... não encontrada para este tokenThe CNPJ is not a company registered under the token
UF da empresa não configuradaThe company record has no state

Examples

# sign = md5(token + path + body + timestamp)
# Template generated from the endpoint path; replace the placeholders
curl -X POST "https://api.tffiscal.com/api/invoice/received/sync" \
  -H "Content-Type: application/json" \
  -H "token: $TOKEN" \
  -H "timestamp: $TIMESTAMP" \
  -H "sign: $SIGN" \
  -d @body.json