Skip to content
Proud to collaborate with Microsoft for Startups

bling.emit-nfse ​

Multi-step emission of an NFS-e (Brazilian services electronic invoice). Validates input, submits via Bling /nfse, polls until the municipality returns AUTHORIZED or REJECTED, and persists the result. The load-bearing piece of the Stripe → NF flow.

Emit an NFS-e at Bling and wait for municipal authorization.

Overview ​

PropertyValue
Workflow typeLinear
LibraryApp-bling
Version1.0

Input Schema ​

FieldTypeRequiredDefaultDescription
organization_uuiduuidYes——
connection_uuiduuidYes——
customer_external_refstringYes—Bling-side contact id of the service recipient
itemsjsonYes—List of service line items. Each item is a dict with at least {service_code, description, unit_price} and optionally {quantity, discount, iss_rate}.
competence_datestringNo—ISO date — mês de competência. Defaults to today.
issue_datestringNo—ISO date — dataEmissao. Defaults to today.
seriesstringNo——
rps_numberstringNo—Pre-issued RPS number; some municipalities require it
order_external_refstringNo—Bling-side order id if this NFS-e is emitted off an order
max_poll_attemptsintegerNo—Polling cap. Default 30 (≈3 min at 6s).
poll_interval_secondsintegerNo—Seconds between polls. Default 6.
idempotency_keystringNo—Caller-provided key to dedupe retries. Stored in extra.
actorstringNo——

Output Schema ​

FieldTypeRequiredDefaultDescription
organization_uuiduuidYes——
connection_uuiduuidYes——
customer_external_refstringYes—Bling-side contact id of the service recipient
itemsjsonYes—List of service line items. Each item is a dict with at least {service_code, description, unit_price} and optionally {quantity, discount, iss_rate}.
competence_datestringNo—ISO date — mês de competência. Defaults to today.
issue_datestringNo—ISO date — dataEmissao. Defaults to today.
seriesstringNo——
rps_numberstringNo—Pre-issued RPS number; some municipalities require it
order_external_refstringNo—Bling-side order id if this NFS-e is emitted off an order
max_poll_attemptsintegerNo—Polling cap. Default 30 (≈3 min at 6s).
poll_interval_secondsintegerNo—Seconds between polls. Default 6.
idempotency_keystringNo—Caller-provided key to dedupe retries. Stored in extra.
actorstringNo——
submitted_external_refstringNo—Bling NFS-e id returned after POST /nfse
submitted_atstringNo——
poll_attemptsintegerNo——
provider_statusstringNo—Last status seen during polling (universal enum string)
rejection_reasonstringNo——
access_keystringNo—Municipal access key when status=AUTHORIZED
pdf_urlstringNo——
xml_urlstringNo——
nfse_numberstringNo——
nfse_seriesstringNo——
commerce_entity_uuiduuidNo—UUID of the persisted commerce_entity row
authorized_atstringNo——
completed_atstringNo——
failure_reasonstringNo——
failed_atstringNo——
_last_contract_dumpjsonNo——
failure_typestringNo——
failed_actionstringNo——
failed_at_statestringNo——
failed_stepjsonNo——
failed_layerjsonNo——
errorstringNo——
error_typestringNo——

States ​

StateInitialTerminalSuccessAuto-advanceDescription
initiatedYesNo—validateEmission requested
pollingNoNo—recordPolling for municipal authorization
submittingNoNo—pollPOSTing NFS-e to Bling
validatingNoNo—submitValidating items + customer
completedNoYesYes—NFS-e authorized + persisted
failedNoYesNo—NFS-e emission failed

State Diagram ​

Transitions ​

FromActionToDescription
initiatedvalidatevalidating—
validatingsubmitsubmitting—
submittingpollpolling—
pollingrecordcompleted—
initiatedfailfailed—
validatingfailfailed—
submittingfailfailed—
pollingfailfailed—

Business Errors ​

CodeMessage Template
BLING_CONNECTION_NOT_FOUNDBling connection {connection_uuid} not found in organization
BLING_CONNECTION_WRONG_PROVIDERConnection {connection_uuid} is not a Bling connection
BLING_NFSE_MISSING_ITEMSAt least one service line item is required to emit an NFS-e
BLING_NFSE_INCOMPLETE_ITEMItem {index}: {missing_field} is required
BLING_NFSE_MISSING_CUSTOMERcustomer_external_ref is required to emit an NFS-e
BLING_NFSE_SUBMIT_FAILEDBling rejected NFS-e submission:
BLING_NFSE_REJECTEDNFS-e rejected by municipality:
BLING_NFSE_TIMEOUTNFS-e {external_id} still {status} after {attempts} poll attempts
BLING_NFSE_PERSIST_FAILEDdata.commerce.entity.persist failed for emitted NFS-e:

API Usage ​

bash
POST /api/workflows/start
Content-Type: application/json

{
  "workflow_type": "bling.emit-nfse",
  "initial_data": {
    "organization_uuid": "value",
    "connection_uuid": "value",
    "customer_external_ref": "value",
    "items": "value"
  }
}