NF-e: validate, issue and follow
Check an NF-e with the dry-run, issue it with an Idempotency-Key and follow its states until it is authorized.
1. Validate (dry-run)
POST /v1/invoices/validate runs the same checks as the real issue, builds the note and checks it against the official layout, but sends nothing to the SEFAZ, reserves no number and charges nothing. It answers the access key the note would have. Add ?includeXml=true to also get the XML.
Request body (the same one to issue)
{
"type": "nfe",
"companyId": "5b8b6a0e-3c6f-4f4e-9a1b-0d7a6d5c2e11",
"recipient": {
"taxId": "123.456.789-09",
"name": "Maria da Silva",
"indIeDest": 9,
"email": "maria@example.com",
"address": {
"street": "Rua das Flores",
"number": "10",
"district": "Centro",
"zip": "01001-000",
"cityCode": "3550308",
"city": "São Paulo",
"state": "SP"
}
},
"items": [
{
"code": "SKU1",
"description": "Camiseta de algodão",
"ncm": "61091000",
"cfop": "5102",
"unit": "UN",
"quantity": 2,
"unitPrice": 10,
"tax": { "csosn": "102" }
}
],
"payments": [{ "tPag": "17", "amount": 20 }]
}Answer 200
{
"data": {
"valid": true,
"accessKeyPreview": "35261111222333000181550010000000011234567891"
}
}When something is wrong the answer is 422 and details lists each field with its path, such as items[1].ncm. The dashboard marks those fields in the form.
Answer 422
{
"statusCode": 422,
"code": "ERROR_NFE_VALIDATION_FAILED",
"type": "validation",
"message": "The NF-e has problems; see details",
"details": [
{ "field": "items[1].ncm", "code": "NCM_INVALID", "message": "NCM must have 8 digits" }
]
}2. Issue
POST /v1/invoices
curl -X POST https://api.corvo.tech/v1/invoices \
-H "X-API-Key: $CORVO_API_KEY" \
-H "Idempotency-Key: pedido-1042" \
-H "Content-Type: application/json" \
-d @nfe.jsonAnswer 202
{
"data": {
"type": "nfe",
"id": "0b7f2f0e-8f43-4f6e-8a35-6a3b0f1d9c77",
"status": "queued"
}
}Idempotency-Key(1 to 200 characters) is required. Repeating the same key with the same body returns the same note (200,replayed: true); the same key with another body answers409IDEMPOTENCY_KEY_REUSED. A retry never issues two notes.recipient.indIeDest:9non-taxpayer (most people),1taxpayer (needsstateRegistration),2exempt.items[].cfop:5xxxinside the state,6xxxfor another state.items[].ncm: 8 digits.items[].tax.csosn:102,101,400or500; left out, the company default applies.paymentsminuschangemust equal the total of the note. Totals are computed by Corvo from the items (each item rounded to cents).payments[].cardis optional. The SEFAZ requires the card group fortPag03 (credit), 04 (debit) and 17 (Pix); if you leave it out, Corvo sendstpIntegra2 (not integrated). Sendcard{tpIntegra,cnpj,tBand,cAut} only for an integrated payment.sendEmail(defaulttrue): when the recipient has an e-mail, the XML and the DANFE are sent after the authorization.- Text fields accept letters, digits and common punctuation. Emoji and line breaks are refused with the field named, before the SEFAZ.
Saved products and customers
To avoid typing the same items again, save them as products of the company. They live in the same favorites as the services: GET /v1/companies/:companyId/service-favorites?kind=product lists them, POST with kind: "product" saves one and DELETE /v1/companies/:companyId/service-favorites/:favoriteId removes it (nfe.documents.view or nfe.documents.issue). Without kind the routes still work as before, for services. A product has description, ncm and unitPrice, and optionally code, gtin, cest, cfop, unit, csosn and origin. Saving the same description again updates the product. Up to 500 per company. On MCP, service_favorite_list, service_favorite_create and service_favorite_delete take kind: "product". In the dashboard, search them on each item, use "Save as product" and see the list in Products.
When an NF-e is accepted, Corvo also saves the recipient in the saved customers (GET /v1/customers/:taxId), now with the address (with the IBGE city code), the indIeDest and the state registration. The NF-e form fills the recipient from it, and you can correct it with PATCH /v1/customers/:taxId (address, indIeDest, stateRegistration) or on the Customers page.
3. Follow
Issuing is asynchronous, like the NFS-e. Read the note with GET /v1/invoices/:id or wait for the webhook. The states are:
| Status | Meaning |
|---|---|
queued, processing | Waiting to be sent, or being sent to the SEFAZ. |
authorized | The SEFAZ authorized it. protocol, authorizedAt and, a moment later, documentsReady appear. |
rejected | The SEFAZ refused it. See lastError. The number is kept: fix it and send again (PUT) or discard it. |
denied | The SEFAZ denied it (final). |
retry_pending | The SEFAZ was unavailable. Corvo tries again by itself. |
reconciliation_required | No answer from the SEFAZ. Corvo checks by the access key, without issuing again. |
manual_review | The check could not confirm. Ask again with POST /v1/invoices/:id/sync. |
cancelling, cancelled | Cancellation requested, then registered. |
discarded | A rejected note that was given up (final). Its number needs an inutilization. |