- Guides
- Issuing NF-e
Guides
Issuing NF-e
Issue NF-e model 55 with or without automatic tax calculation.
POST /nfe issues an NF-e model 55 for the organization given in the x-organization-id header, authenticated by the Enterprise key.
With or without tax calculation
With calculation (Payload Inteligente)
Without calculation (default)
Treeunfe calculates the taxes for each item and the totals (ICMS, ST, DIFAL, FCP, IPI, PIS, COFINS, IBS, and CBS) using the organization’s issuing rules.
Use this when your system doesn’t have its own tax engine.
Body structure
{
"calculateTaxes": true,
"NFe": {
"infNFe": {
"ide": { },
"emit": { },
"dest": { },
"autXML": [ ],
"det": [
{ "prod": { }, "imposto": { } }
],
"total": { },
"transp": { },
"pag": { },
"infRespTec": { }
}
}
}
| Field | Description |
|---|---|
calculateTaxes | true to have Treeunfe calculate the taxes (Payload Inteligente); false (default) to send the taxes already calculated. |
NFe.infNFe | The invoice groups, with the same tags as the official NF-e layout (MOC). |
Tag names follow the SEFAZ layout. The only difference is CNPJCPF: send either the CNPJ or the CPF in this one field, digits only.
Main groups
| Group | Contents |
|---|---|
ide | Identification: state, series, number, dates, operation type, purpose. |
emit | Issuer: CNPJ, legal name, address (enderEmit), state registration (IE), and CRT. |
dest | Recipient: CNPJ/CPF, name, address (enderDest), indIEDest, email. |
autXML | CNPJs/CPFs authorized to download the XML. |
det | The invoice items, one object per product: prod (product data) and imposto (taxes). In the Payload Inteligente, each item only needs cProd, qCom, and vUnCom. |
total | Totals: ICMSTot and IBSCBSTot. |
transp | Shipping. modFrete: 9 = no freight. |
pag | Payment (detPag). |
infRespTec | Technical contact responsible for the system. |
The invoice’s environment comes from the Enterprise key: a sandbox key issues in the sandbox and a production key in production. Do not send the environment in the payload.
Payload Inteligente (with calculation)
With calculateTaxes: true, send only the essentials: the recipient’s CNPJ or CPF in dest and, for each item, the product code, the quantity, and the unit price. Treeunfe fills in the rest of the invoice (identification, issuer, recipient, product data, taxes, totals, transport, and payment) from the company’s records and settings.
{
"calculateTaxes": true,
"NFe": {
"infNFe": {
"dest": "11222333000181",
"det": [
{ "prod": { "cProd": "6658", "qCom": 1, "vUnCom": 100 } }
]
}
}
}
| Field | Description |
|---|---|
dest | The recipient’s CNPJ or CPF, digits only. |
det[].prod.cProd | The product code in the product records. |
det[].prod.qCom | Quantity. |
det[].prod.vUnCom | Unit price. |
How the issuing rule is chosen
With calculateTaxes: true, each item is calculated by an issuing rule. The rule can be chosen in two ways:
| Method | How it works | When to use |
|---|---|---|
| Automatic assignment | Without taxRuleId on the item, Treeunfe picks the rule by matching the invoice type and purpose (tpNF and finNFe), the state, and the product’s NCM. | Sales. |
| Assignment by ID | With taxRuleId on the item, Treeunfe applies that rule and skips the automatic choice. | Fixed-pattern operations: shipments (remessa), returns, consignment, demonstration, and repair. |
Shipments, returns, consignment, demonstration, and repair have the same invoice type and purpose as a sale (tpNF: 1 and finNFe: 1). With automatic assignment, these items fall under the sales rule and are taxed as a sale. Send taxRuleId on these items.
Setting the rule on an item
Send taxRuleId on the item, after prod. In the example, the first item uses the REM01 rule and the second uses automatic assignment:
{
"calculateTaxes": true,
"NFe": {
"infNFe": {
"dest": "11222333000181",
"det": [
{ "prod": { "cProd": "6658", "qCom": 1, "vUnCom": 100 }, "taxRuleId": "REM01" },
{ "prod": { "cProd": "7710", "qCom": 2, "vUnCom": 50 } }
]
}
}
}
taxRuleId accepts:
- the rule identifier, set in the issuing rule’s record (for example,
REM01); - the rule’s internal ID (for example,
6b1f3c2a-8d4e-4f7a-9c21-5e0a7b9d3f10).
The rule sets the CFOP (in-state or interstate according to idDest, including for recipients that are not ICMS taxpayers), the ICMS CST and rate, the FCP indicator, the IPI CST and classification code (cEnq), and the PIS and COFINS CST and rate. Treeunfe still calculates the tax amounts and the totals.
On an invoice with mixed items, each item follows its own case: with taxRuleId, it uses that rule; without taxRuleId, it uses automatic assignment.
If no rule of the organization matches the ID or identifier sent, the API returns 400 with the message Regra de emissão não encontrada.
Rule identifier
The Issuing rule identifier field is on the rule’s create and edit screen. It is optional and lets your system use its own code, such as VEN02, instead of the internal ID.
- Use letters and numbers only, up to 20 characters.
- The identifier can’t repeat across the rules of the same organization, including the system’s default rules.
- The system’s default rules already come with an identifier.
In the Enterprise account, the company registers its own issuing rules and identifiers through the rule-sharing link. See Fiscal configuration.
Full example
Tax regime
The example below uses the normal regime (emit.CRT: 3, ICMS CST 00). For Simples Nacional, use emit.CRT: 1 and the ICMSSN groups with CSOSN (for example, ICMSSN102).
Response
When SEFAZ authorizes the invoice:
{
"outcome": "SUCCESS",
"chaveAcesso": "41261012345678000195554650000000101585524161",
"protocolo": "141260000000000"
}
Response statuses
| Status | Meaning |
|---|---|
200 | Invoice processed. Check outcome. |
400 | Invalid body. |
401 | x-enterprise-key missing or invalid. |
402 | Issuing blocked by the account’s plan or balance. |
403 | Organization inactive, or the key lacks the nfe:emit scope. |
422 | Invoice rejected during validation or by SEFAZ. |
503 | SEFAZ unavailable. Try again later. |
See also Errors.