Sudrel API
Dashboard Create API key

Documentation › NF-e issuance

Guides

NF-e contingency

When a state's SEFAZ goes down: wait, SVC or EPEC, without ever creating a duplicate invoice.

When the SEFAZ of the company's state goes down, the invoice can wait or go out in contingency. The rule that always applies: only an invoice that certainly never reached SEFAZ goes to contingency. An invoice that was sent and got no response, or that has ever been in aguardando_confirmacao, stays in aguardando_confirmacao and is resolved by querying the key when the state is back, under any policy. This is what prevents two NF-e for the same sale.

Company policy

politica_contingencia in the tax profile (PUT /v1/nfe/perfil-fiscal/{empresa_id}):

Policy Invoice that never went out Invoice sent without a response
esperar (default) Stays transmitindo (falha_envio.motivo: uf_indisponivel) and goes out when the state is back Stays aguardando_confirmacao
svc Goes to the state's SEFAZ Virtual de Contingência, if the state has activated it Stays aguardando_confirmacao
epec Registers the EPEC in the Ambiente Nacional and transmits to the state when it is back Stays aguardando_confirmacao

The svc policy does not issue if the state's SEFAZ has not activated SVC: the invoice waits, with the reason. PR and PB do not accept EPEC: the invoice waits.

SVC (SEFAZ Virtual de Contingência)

The invoice goes out with tpEmis 6 (SVC-AN) or 7 (SVC-RS, the one for Bahia), with the contingency start date and the reason in the XML and the DANFE. The key changes with tpEmis; the number stays the same, because the original key never went out (it is kept in contingencia.chave_original and in chaves_anteriores). Once authorized in SVC, the invoice does not go back to the state: SVC shares it. Cancellation goes to SVC itself; a correction letter goes to the state (SVC has no CC-e).

EPEC

The invoice goes out with tpEmis 4 and the EPEC event (invoice summary) is registered in the Ambiente Nacional. With it, the DANFE is already valid: GET /v1/nfe/{id}/danfe carries the EPEC protocol, the reason and the contingency time. The NF-e goes to the state as soon as it is back, with the same key and the same data. The deadline is 168 hours from the EPEC; with 24 left, the NFE_CONTINGENCIA webhook warns you. If the state rejects the NF-e, the correction cannot change the recipient, issue date, total, ICMS or ICMS-ST (they are the EPEC data): contingencia.epec.correcao explains.

Reconciliation

When the state is back, Sudrel queries the original key of every invoice that went to contingency. If it exists at SEFAZ (which should not happen), the original is cancelled within 24 hours, you receive NFE_CONTINGENCIA with contingencia.situacao: duplicata_cancelada and the Sudrel team handles the case as an incident.

State status

GET /v1/sefaz/status shows each state with recent issuance in your key's environment: normal, instavel (a bad signal, issuance does not change) or indisponivel, based on the SEFAZ service status and the actual transmission failure rate, and whether SVC is activated. When it changes: the SEFAZ_STATUS_ALTERADO webhook.

Sources: NT 2013.007 v1.03 (SVC) and NT 2014.001 v1.41 (EPEC), from the Portal Nacional da NF-e.

Endpoints in this section, with in-page testing