POST
/api/invoice/received/syncSync received documents
Required headers
tokenstring | string | Company token |
signstring | string | MD5 signature: MD5(token + path + body + timestamp) |
timestampstring | string | Unix timestamp in seconds (5-minute window) |
Fields
| Field | Type | Required | Description |
|---|---|---|---|
| cnpj | string | Yes | Recipient company CNPJ — 14 digits, unformatted. Must be a company registered under the token |
| max_ | int | No | Maximum 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
ultNSUsaved by the company's previous synchronization - Loops calling tax authority until
cStat ≠ 138ormax_iterationsis reached - Decompresses the returned XMLs (gzip)
- Saves each document and stores its XML for download through
/received/get_xml - Updates the synchronization progress (
ultNSUandmaxNSU) - 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
cnpjstring | string | Recipient CNPJ queried |
ufstring | string | Recipient state used in the query |
initial_long | long | Starting NSU — the last one processed before this run |
ult_long | long | New last NSU after the sync |
max_long | long | Largest NSU available in the national environment (AN) at the time of the query |
pendinglong | long | Documents still pending (max_nsu - ult_nsu).If > 0, call /sync again to download the rest |
iterationsint | int | How many tax authority calls were made in this run |
last_int | int | Last cStat returned by the tax authority.137 is normal end, 656 is rate limit |
last_string | string | tax authority descriptive return message for the last call |
statsobject | object | |
resNFeint | int | Number of NFe summaries downloaded in this run |
procNFeint | int | Number of full NFes downloaded |
resEventoint | int | Number of event summaries downloaded |
procEventoint | int | Number of full events downloaded |
skippedint | int | Documents skipped (NSU already saved, unrecognized document type, or a parse error in an individual document) |
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
| Message | Cause |
|---|---|
| Informe o cnpj / 请传入cnpj | cnpj was not sent |
| empresa com CNPJ ... não encontrada para este token | The CNPJ is not a company registered under the token |
| UF da empresa não configurada | The 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
{
"cnpj": "26638419000167",
"max_iterations": 50
}
{
"success": true,
"message": "成功",
"data": {
"cnpj": "26638419000167",
"uf": "SP",
"initial_nsu": 0,
"ult_nsu": 2323,
"max_nsu": 2323,
"pending": 0,
"iterations": 8,
"last_cstat": 137,
"last_motivo": "Nenhum documento localizado",
"stats": {
"resNFe": 3,
"procNFe": 4,
"resEvento": 336,
"procEvento": 5,
"skipped": 0
}
}
}