SonaCORE

Referência / Quadra Command API

Fiscal Documents

2 operações em Quadra Command API 0.2.0.

POST/v1/fiscal-documents

Record a fiscal document

Record a fiscal document — an NFS-e, a guia, a comprovante, a declaração or a recibo — in its kind's initial state: `RASCUNHO` for an NFS-e, `EMITIDO` for every other kind.

Core stores **references only**. The XML and the PDF live in the tenant backend's object store; a `storage_ref` names the object and carries its sha256. Requires an `Idempotency-Key` header: a create has no prior state to be idempotent on.

Raises: 404: ACCOUNT_NOT_FOUND 409: IDEMPOTENCY_KEY_REUSED 422: INVALID_FISCAL_KIND, INVALID_REFERENCE, or a model validation error (including any field the model does not declare)

Parâmetros

NomeTipoDetalhe
Idempotency-Keystringheaderobrigatório

Corpo da requisição

CreateFiscalDocumentRequest — obrigatório. Os campos estão listados em Esquemas, abaixo.

Respostas

StatusCorpoDetalhe
201FiscalDocumentResponseResposta bem-sucedida
422HTTPValidationErrorErro de validação
POST/v1/fiscal-documents/{doc_id}/transitions

Move a fiscal document to its next state

Move a fiscal document along its kind's state machine — for an NFS-e, `RASCUNHO → EM_PROCESSAMENTO → AUTORIZADA | REJEITADA`, then `AUTORIZADA → CANCELADA | SUBSTITUIDA`.

⭐ **A replay is a 200 no-op, never an error.** Repeating a transition that already happened — or asking for one the current state does not allow — returns the document unchanged with `applied: false` and a `noop_reason`. A provider callback is delivered more than once as a matter of course.

A rejection must carry **both** `reason` (the text shown to the user) and `provider_code` (the technical code support needs). An NFS-e entering `AUTORIZADA` must carry its 50-character `chave`, which is unique per tenant.

Raises: 404: FISCAL_DOCUMENT_NOT_FOUND (unknown and foreign ids are the same miss) 409: CHAVE_CONFLICT (the chave is recorded against another document) 422: INVALID_FISCAL_STATE, REJECTION_INCOMPLETE, CHAVE_REQUIRED, CHAVE_IMMUTABLE, CHAVE_NOT_APPLICABLE, INVALID_CHAVE, INVALID_REFERENCE

Parâmetros

NomeTipoDetalhe
doc_idstringpathobrigatório

Corpo da requisição

FiscalTransitionRequest — obrigatório. Os campos estão listados em Esquemas, abaixo.

Respostas

StatusCorpoDetalhe
200FiscalTransitionResponseResposta bem-sucedida
422HTTPValidationErrorErro de validação

Esquemas

Os modelos que as operações acima aceitam e devolvem. Campos opcionais estão marcados como tal; um campo tipado como outro modelo está documentado sob o nome dele.

CreateFiscalDocumentRequest

Create a fiscal document in its kind's initial state. An NFS-e is born ``RASCUNHO``; every other kind is born ``EMITIDO``.

CampoTipoDetalhe
account_idstringobrigatórioThe company account this document belongs to
amountsobject, opcionalNamed centavo amounts, e.g. gross_cents, withheld_cents, iss_cents
competenciastring, opcionalYYYY-MM the document is attributed to
counterpartyFiscalParty, opcional
issuerFiscalParty, opcional
kind"NFSE" | "GUIA" | "COMPROVANTE_RETENCAO" | "COMPROVANTE_PAGAMENTO" | "DECLARACAO_OPTANTE" | "RECIBO_PROLABORE"obrigatório
obligation_idsarray de string, opcional
provider_refsobject, opcionalProvider identifiers (protocolo, número, provider_id) — not the chave
replacesstring, opcionalThe fdoc_ id this document substitutes
storage_refsarray de StorageRef, opcional

FiscalDocumentResponse

A fiscal document's head and history.

CampoTipoDetalhe
account_idstring, opcional
amountsobject, opcional
chavestring, opcional
competenciastring, opcional
counterpartyobject, opcional
created_atstringobrigatório
doc_idstringobrigatório
event_seqintegerobrigatório
historyarray de object, opcionalThe immutable per-transition records, in order
issuerobject, opcional
kindstringobrigatório
obligation_idsarray de string, opcional
provider_refsobject, opcional
rejectionobject, opcional{reason, provider_code, at} — the human text AND the technical code
replaced_bystring, opcional
replacesstring, opcional
statestringobrigatório
state_historyarray de object
storage_refsarray de object, opcional
tenantstringobrigatório
updated_atstringobrigatório

FiscalParty

Issuer or counterparty, as the document names them.

CampoTipoDetalhe
account_idstring, opcional
municipio_ibgestring, opcional
namestring, opcional
tax_idstring, opcionalCPF (11) or CNPJ (14), digits only

FiscalTransitionRequest

Move a document to its next state. ⭐ Replaying the same transition is a **200 no-op** (``applied: false``), never an error: a provider callback arrives more than once as a matter of course.

CampoTipoDetalhe
chavestring, opcionalNFS-e chave de acesso (50 characters)
provider_codestring, opcionalProvider's technical code (required on REJEITADA)
provider_refsobject, opcional
reasonstring, opcionalHuman-readable reason (required on REJEITADA)
replaced_bystring, opcional
storage_refsarray de StorageRef, opcional
to_statestringobrigatório

FiscalTransitionResponse

CampoTipoDetalhe
account_idstring, opcional
amountsobject, opcional
appliedbooleanobrigatórioFalse when the transition was a no-op
chavestring, opcional
competenciastring, opcional
counterpartyobject, opcional
created_atstringobrigatório
doc_idstringobrigatório
event_seqintegerobrigatório
historyarray de object, opcionalThe immutable per-transition records, in order
issuerobject, opcional
kindstringobrigatório
noop_reasonstring, opcionalALREADY_IN_STATE (a replay) | NOT_ALLOWED_FROM_STATE
obligation_idsarray de string, opcional
provider_refsobject, opcional
rejectionobject, opcional{reason, provider_code, at} — the human text AND the technical code
replaced_bystring, opcional
replacesstring, opcional
statestringobrigatório
state_historyarray de object
storage_refsarray de object, opcional
tenantstringobrigatório
updated_atstringobrigatório

HTTPValidationError

CampoTipoDetalhe
detailarray de ValidationError

StorageRef

A pointer to a document the BFF stores — never the document. ``sha256`` is what makes the ref evidence: contabil-06's export manifest lists it per item, so an archive can be checked against the ledger's own record.

CampoTipoDetalhe
keystringobrigatórioThe object key in that store — an identifier, never content
media_type"application/xml" | "application/pdf"obrigatórioWhat the object is
sha256stringobrigatórioLower-case hex sha256 of the stored bytes
size_bytesinteger, opcional
storestringWho holds the bytes. Only the tenant's backend does today.Padrão "bff"

ValidationError

CampoTipoDetalhe
ctxobject
inputnão declarado
locarray de string ou integerobrigatório
msgstringobrigatório
typestringobrigatório