/api/invoice/v2/createIssue NF-e asynchronously
The request body and validation are identical to /api/invoice/create. The difference is that it does not wait for the tax authority: once validated, the request is queued and the receipt number task_id is returned immediately; issuance completes in the background. Fetch the result by polling /api/invoice/v2/task/get or receive it on the webhook address configured in the portal (see “Webhook callbacks” below).
Required headers
tokenstring | string | Issuing company token |
signstring | string | MD5 signature |
timestampstring | string | Unix timestamp in seconds |
Body
/api/invoice/create (cliente, products[], pag_info…) and are not repeated here. A callback_url in the request is ignored: the callback address comes only from the portal configuration.is_boolean | boolean | Skips deduplication by id and issues a new NF-e (new number), as in v1 — it does not change or overwrite the previous invoice.v2 task reuse (below) does not consider this field |
Processing rules
| Rule | Description |
|---|---|
| Idempotency | When id is sent, a task from the same CNPJ created in the last 5 minutes (pending, processing or successful) with the same key — id, ambiente, transaction_type (0≡2, 1≡3), client CPF/CNPJ and CEP — is reused: the response has the same task_id and the current status. Products and amounts are not part of the key: use a different id for a different order. Without id there is no deduplication. |
| Rate limit | At most 100 pending or processing tasks per CNPJ per minute; beyond that the response is Rate limit exceeded for this CNPJ. If the balance does not also cover the tasks still queued, the response is Saldo insuficiente considerando as notas ainda em processamento…. |
| Status | pending on acceptance, processing while running, final success / failed. |
Response fields
task_string | string | Task number, used for polling and callback deduplication |
idstring | string | Business id from the request (empty if not sent) |
statusstring | string | Task status: pending for a new task; when the task is reused, its current status |
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/v2/create" \ -H "Content-Type: application/json" \ -H "token: $TOKEN" \ -H "timestamp: $TIMESTAMP" \ -H "sign: $SIGN" \ -d @body.json
{
"id": "PED-1001",
"nature_of_operation": "Venda de mercadoria",
"transaction_type": "1",
"model": "55",
"issuance_type": "1",
"ambiente": "2",
"cliente": { "cpf": "26443880072", "name": "Nome do Destinatário", "endereco": "Rua Example",
"numero": "100", "bairro": "Centro", "city": "São Paulo", "uf": "SP", "cep": "01310100" },
"products": [ { "codigo": "P1", "name": "Produto", "ncm": "10063021", "count": 1, "unit": "UN",
"unit_price": 100, "total_price": 100, "origem": 0, "indicador_total": 1,
"category_id": "CATEGORY_ID" } ],
"pag_info": [ { "payment_method": "01", "payment_indicator": "0", "payment_value": 100 } ]
}{
"success": true,
"message": "Recebido. Consulte o resultado via /api/invoice/v2/task/get (task_id) ou aguarde o callback. Não reenvie.",
"task_id": "66d0a1b2c3d4e5f6a7b8c9d0",
"id": "PED-1001",
"status": "pending"
}{ "success": false, "message": "Rate limit exceeded for this CNPJ, please slow down" }Webhook callbacks (issuance result push)
When an asynchronous issuance task reaches a final state, the platform pushes one result notification to the address configured by the integrator. Push and polling can be combined: rely on the callback and use polling as a fallback.
Configuration and address requirements
- The Webhook URL is configured in the main platform under “My Account → Webhook URL”; the “Send test” button on the same page verifies it.
- Integrators that previously configured a Webhook URL on an application in the former developer portal retain that configuration; it remains in effect and takes precedence over the address in the My Account.
- A request-level
callback_urlis not supported and is ignored. - The address must be a public http(s) URL, never a private or loopback address; redirects are not followed (3xx counts as failure); timeout 10 s; any 2xx counts as delivered.
Delivery timing and retries
- Delivered once immediately after the task reaches
success/failed. - On failure, retried at +1 min, +10 min, +60 min, +4 h and +12 h, 6 attempts in total (about 17 hours); after that delivery stops and
/api/invoice/v2/task/getremains available as a fallback. - Delivery is at-least-once; deduplicate by
task_id.
Payload (decrypted)
| Field | Type | Description |
|---|---|---|
| task_ | string | Task number, deduplication key |
| id | string | Business id from the request |
| company_ | int | Issuing company ID |
| cnpj | string | Issuing company CNPJ |
| status | string | success / failed |
| result | object | On success, the same response object as /api/invoice/create plus data.danfe (DANFE PDF URL) and, when the label is selected, data.danfe_etiqueta (100×150 mm label URL). The formats are set under "My Account → Webhook PDF format", and both may be selected: when A4 is selected (default), data.danfe contains the A4 DANFE; when only the label is selected, both data.danfe and data.danfe_etiqueta contain the label; null on failure |
| error | string | Failure reason, tax authority rejection reason when available; empty string on success |
| test | boolean | Present and true only on messages sent by the portal “Send test” button; receivers should ignore them |
{
"task_id": "66d0a1b2c3d4e5f6a7b8c9d0",
"id": "PED-1001",
"company_id": 1263,
"cnpj": "12345678000199",
"status": "success",
"result": {
"success": true,
"message": "成功",
"data": {
"uuid": "4663a257-adf1-4561-971f-6aaffbd30ca8",
"status": "Success",
"motivo": "Rejeição 100: Autorizado o uso da NF-e",
"nfe": 100, "serie": 1,
"chave": "35260112345678000199550010000001001000000017",
"modelo": "nfe", "epec": false,
"xml": "https://oss.example.com/.../chave.xml",
"danfe": "https://oss.example.com/.../chave.pdf",
"danfe_etiqueta": "https://oss.example.com/.../chave_etiqueta.pdf"
}
},
"error": ""
}Encrypted envelope
Payloads are delivered encrypted with AES-256-GCM. The key is derived from the integrator’s API key, so no extra secret is exchanged: key = SHA-256(UTF-8(token)), where token is the integrator token (main platform “My Account → Key”). GCM provides integrity: tampering with any field (including ts) makes decryption fail, so no separate signature header is added.
Headers: X-Webhook-Timestamp (Unix seconds, equal to the envelope ts) and X-Webhook-Encryption: A256GCM. If no key can be resolved the payload is delivered in plain text without the X-Webhook-Encryption header; receivers should branch on that header.
Decryption: nonce, payload and tag are Base64; the additional authenticated data (AAD) is the decimal string of ts (UTF-8).
POST {webhook_url}
Content-Type: application/json
X-Webhook-Timestamp: 1786990396
X-Webhook-Encryption: A256GCM
{
"enc": "A256GCM",
"kid": "token",
"ts": 1786990396,
"nonce": "<base64, 12 bytes>",
"payload": "<base64 ciphertext>",
"tag": "<base64, 16 bytes>"
}Python decryption example (cryptography)
import base64, hashlib, json
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
def decrypt(token, body):
env = json.loads(body)
key = hashlib.sha256(token.encode("utf-8")).digest()
aad = str(env["ts"]).encode("utf-8")
data = base64.b64decode(env["payload"]) + base64.b64decode(env["tag"])
plain = AESGCM(key).decrypt(base64.b64decode(env["nonce"]), data, aad)
return json.loads(plain)Node.js decryption example
const crypto = require("crypto");
function decrypt(token, body) {
const env = JSON.parse(body);
const key = crypto.createHash("sha256").update(token, "utf8").digest();
const d = crypto.createDecipheriv("aes-256-gcm", key, Buffer.from(env.nonce, "base64"));
d.setAAD(Buffer.from(String(env.ts), "utf8"));
d.setAuthTag(Buffer.from(env.tag, "base64"));
const plain = Buffer.concat([d.update(Buffer.from(env.payload, "base64")), d.final()]);
return JSON.parse(plain.toString("utf8"));
}Integration testing
- The “Send test” button next to the webhook URL in the portal sends an encrypted test message (
test: true) to that address to verify connectivity and decryption. - The system test inbox (
/webhook/inbox/{slot},slotbeing any identifier of your choice) can also be configured as the webhook URL; decrypted messages are then visible in the portal.