/api/tax/purchasePurchase credit × cost
For each purchase item, returns how much of each tax is recoverable (credit) and how much goes into cost, plus the taxes the buyer itself owes on entry (DIFAL, FCP and partial advance payment). This is the data used to split inventory/cost and recoverable tax when posting the invoice.
The call only calculates: nothing is stored and the tax authority is not queried. The buyer is the token company. Two modes: previsao (purchase order, before the invoice: the engine calculates what the supplier should itemize) and nota (invoice already synchronized by /api/invoice/received/sync: uses the amounts itemized in the stored XML). When data is missing or a rule is ambiguous, the item returns a pending item and no rate is assumed.
Required headers
tokenstring | string | Company token; CNPJ, state and tax regime are read from the company's registration |
signstring | string | MD5 signature: md5(token + "/api/tax/purchase" + body without line breaks + timestamp) |
timestampstring | string | Unix timestamp in seconds, 5-minute tolerance |
Body
modo*string | string | previsao or nota |
chavestring | string | nota mode: 44-digit key of an invoice received by the token CNPJ |
data_string | string | previsao mode: YYYY-MM-DD; defines the rules and rates in force.Date-time (ISO 8601) is also accepted |
data_string | string | nota mode, optional: entry date; defaults to the issue date |
regime_string | string | real or presumido (CRT 3).Overrides the company registration |
fornecedorobject | object | previsao mode: cnpj, uf, crt (1 to 4) and industrial (manufacturer: calculates the IPI it would itemize) |
finalidadestring | string | Default purpose of the items |
itens[]array | array | |
finalidade*string | string | revenda, industrializacao, uso_consumo or ativo_imobilizado (or the default) |
insumoboolean | boolean | Use and consumption under lucro real: is the good an input for PIS/COFINS? Without it, pending item insumo_a_confirmar |
ncmstring | string | previsao: ncm, quantidade + valor_unitario or valor_total, frete, seguro, outras_despesas, desconto, origem, ex_tipi; pCredSN for a Simples Nacional supplier.A value that is not a number: pending item valor_invalido; nonexistent NCM: ncm_inexistente; discount larger than the value: desconto_maior_que_valor |
nItemint | int | nota mode: invoice item the purpose refers to |
detalhadoboolean | boolean | Includes the legal basis of each tax and the table versions |
* Required field.
Company registration: regime_federal and contribuinte_ipi (true/false) in /api/company/edit. Without contribuinte_ipi, an item with itemized IPI returns the pending item contribuinte_ipi_ausente.
Rules by tax
| Tax | Treatment |
|---|---|
| ICMS | Resale and manufacturing: credit (LC 87/1996, art. 20). Use and consumption: cost. Fixed assets: credit through CIAP in 48 instalments (the taxed-output factor is applied by the ERP). Simples Nacional supplier: only the informed credit (vCredICMSSN / pCredSN). Buyer under the Simples Nacional or MEI: no credit, ICMS goes to cost (LC 123/2006, art. 23) |
| ICMS-ST | Cost. Invoice with ST for manufacturing: pending item st_industrializacao |
| DIFAL / FCP | Interstate purchase for use and consumption or fixed assets: base × (internal − interstate), single or double base according to the buyer state rule (uf_regra_compra table); without a rule, pending item difal_base_sem_regra. IPI is part of the base. Use and consumption: cost; fixed assets: CIAP. When the invoice has ICMS-ST withheld, DIFAL is not added (warning difal_coberto_pela_st) |
| Partial advance payment | Interstate purchase for resale, according to the buyer state rule; without a rule nothing is calculated and the warning antecipacao_parcial_sem_regra is returned |
| IPI | Buyer that is an IPI taxpayer, for resale or manufacturing: credit. Other cases: cost. Buyer under the Simples (CRT 1, 2 and 4): cost |
| PIS / COFINS | Lucro real: 1.65% and 7.6% on the value without IPI and without the itemized ICMS, for resale and manufacturing (use and consumption only with insumo = true). Fixed assets: base only, for the credit on depreciation. Single-phase product for resale, lucro presumido and Simples: no credit |
| IBS / CBS | 2026: informational only, no effect on cost |
Own ICMS is already inside the price and only enters through the credit side. Each item satisfies custo_aquisicao + total_recuperavel = desembolso; the engine checks it and, if it does not match, the item is parcial with the warning fechamento_divergente.
Response fields
statusstring | string | determinado, parcial or pendente (the worst among the items) |
comprador/fornecedor/emitente/notaobject | object | Data used in the calculation; emitente and nota in nota mode |
itens[]array | array | |
tributosobject | object | Per tax: destacado or devido, recuperavel and custo; PIS and COFINS with base_credito, aliquota and recuperavel |
ciapobject | object | total, parcela (1/48) and parcelas |
desembolsonumber | number | Operation value plus the taxes paid outside the price |
total_number | number | Sum of the credits |
custo_number | number | Outlay minus credits |
itens[].array | array | Stable codigo and mensagem |
totaisobject | object | Sums of the calculated items |
Common errors
| Message | Cause |
|---|---|
| Empresa não cadastrada para este token / 该token未关联公司 | The token is not linked to a registered company |
| Corpo da requisição inválido: envie um objeto JSON / 请求体无效,请传入 JSON 对象 | The body is not a valid JSON object |
| Falha no cálculo da compra. Tente novamente mais tarde. / 采购税额计算失败,请稍后重试 | Internal calculation failure; the request can be retried later |
Examples
# sign = md5(token + path + body + timestamp) # Template generated from the endpoint path; replace the placeholders curl -X POST "https://api.tffiscal.com/api/tax/purchase" \ -H "Content-Type: application/json" \ -H "token: $TOKEN" \ -H "timestamp: $TIMESTAMP" \ -H "sign: $SIGN" \ -d @body.json
custo_aquisicao = vProd + vFrete + vSeg + vOutro − vDesc
+ IPI + ICMS-ST
+ DIFAL + FCP + antecipacao_parcial
− Σ recuperavel
{
"modo": "previsao",
"data_operacao": "2026-11-10",
"fornecedor": { "cnpj": "11444777000161", "uf": "PR", "crt": 3, "industrial": true },
"itens": [
{ "ncm": "94036000", "origem": 0, "quantidade": 1, "valor_unitario": 1000.00,
"finalidade": "uso_consumo", "insumo": false }
]
}
{
"success": true,
"data": {
"status": "determinado",
"modo": "previsao",
"comprador": { "CNPJ": "11222333000181", "UF": "SP", "CRT": 3, "regime_federal": "real", "contribuinte_ipi": false },
"itens": [{
"nItem": 1, "status": "determinado", "finalidade": "uso_consumo",
"valor_item": 1000.00, "valor_operacao": 1000.00,
"tributos": {
"ICMS": { "destacado": 120.00, "recuperavel": 0.00, "custo": 120.00 },
"ICMS_ST": { "destacado": 0.00, "recuperavel": 0.00, "custo": 0.00 },
"DIFAL": { "devido": 63.00, "base": 1050.00, "tipo_base": "unica", "aliquota_interna": 18.0,
"aliquota_interestadual": 12.0, "recuperavel": 0.00, "custo": 63.00 },
"FCP": { "devido": 0.00, "recuperavel": 0.00, "custo": 0.00 },
"ANTECIPACAO_PARCIAL": { "devido": 0.00, "base": 0.00, "recuperavel": 0.00, "custo": 0.00 },
"IPI": { "destacado": 50.00, "recuperavel": 0.00, "custo": 50.00 },
"PIS": { "base_credito": 0.00, "aliquota": 0.00, "recuperavel": 0.00 },
"COFINS": { "base_credito": 0.00, "aliquota": 0.00, "recuperavel": 0.00 },
"IBSCBS": { "vIBS": 1.00, "vCBS": 9.00, "informativo": true }
},
"ciap": { "total": 0.00, "parcela": 0.00, "parcelas": 48 },
"desembolso": 1113.00, "total_recuperavel": 0.00, "custo_aquisicao": 1113.00,
"pendencias": [], "avisos": []
}],
"totais": { "custo_aquisicao": 1113.00, "total_recuperavel": 0.00, "desembolso": 1113.00 }
}
}