Invoices (NF-e)

Overview

'Invoices (NF-e): you send the XML, marketapi validates it and sends it to the marketplace.'

marketapi does not issue invoices (NF-e). You send the already authorized XML, marketapi validates it and sends it to the marketplace in a job. On many marketplaces the invoice blocks shipping, so it comes before the label.

The whole journey: The order lifecycle.

Endpoints

MethodPathWhat it does
GET/v1/orders/{orderId}/invoicesList order invoices
POST/v1/orders/{orderId}/invoicesSend invoice
GET/v1/invoices/{invoiceId}Get invoice
GET/v1/invoices/{invoiceId}/xmlDownload invoice XML

Flow

  1. Upload the XML as a confidential asset.
  2. Call Send invoice with the xmlAssetId. The invoice is born pending, and so is the order invoiceStatus.
  3. The invoice.submit job sends it to the marketplace. The invoice moves to submitted.
  4. The marketplace answers: accepted or rejected. The webhook arrives, and the order changes with it.

Validation

Before creating the job, marketapi checks the XML. If it fails, the answer is 422 with details.reason, and nothing is saved: invoice_xml_invalid, invoice_not_authorized, invoice_access_key_invalid, invoice_issuer_mismatch or invoice_total_mismatch.

Other refusals are 409: repeated key, cancelled order, or an invoice that was not rejected already exists. To replace a rejected one, send replacesInvoiceId.

States

statusMeaning
pendingvalidated, not sent yet
submittedsent, waiting for the marketplace
acceptedaccepted
rejectedrejected; see statusReasons

Webhooks

invoice.accepted and invoice.rejected. They do not carry the issuer tax ID.

Legal custody of the XML is yours, as issuer. marketapi keeps a confidential copy for the order retention period.