Referência / Quadra Command API
Fiscal Documents
2 operações em Quadra Command API 0.2.0.
/v1/fiscal-documentsRecord 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
| Nome | Tipo | Detalhe |
|---|---|---|
| Idempotency-Key | string | headerobrigatório |
Corpo da requisição
CreateFiscalDocumentRequest — obrigatório. Os campos estão listados em Esquemas, abaixo.
Respostas
| Status | Corpo | Detalhe |
|---|---|---|
| 201 | FiscalDocumentResponse | Resposta bem-sucedida |
| 422 | HTTPValidationError | Erro de validação |
/v1/fiscal-documents/{doc_id}/transitionsMove 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
| Nome | Tipo | Detalhe |
|---|---|---|
| doc_id | string | pathobrigatório |
Corpo da requisição
FiscalTransitionRequest — obrigatório. Os campos estão listados em Esquemas, abaixo.
Respostas
| Status | Corpo | Detalhe |
|---|---|---|
| 200 | FiscalTransitionResponse | Resposta bem-sucedida |
| 422 | HTTPValidationError | Erro 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``.
| Campo | Tipo | Detalhe |
|---|---|---|
| account_id | string | obrigatórioThe company account this document belongs to |
| amounts | object, opcional | Named centavo amounts, e.g. gross_cents, withheld_cents, iss_cents |
| competencia | string, opcional | YYYY-MM the document is attributed to |
| counterparty | FiscalParty, opcional | |
| issuer | FiscalParty, opcional | |
| kind | "NFSE" | "GUIA" | "COMPROVANTE_RETENCAO" | "COMPROVANTE_PAGAMENTO" | "DECLARACAO_OPTANTE" | "RECIBO_PROLABORE" | obrigatório |
| obligation_ids | array de string, opcional | |
| provider_refs | object, opcional | Provider identifiers (protocolo, número, provider_id) — not the chave |
| replaces | string, opcional | The fdoc_ id this document substitutes |
| storage_refs | array de StorageRef, opcional |
FiscalDocumentResponse
A fiscal document's head and history.
| Campo | Tipo | Detalhe |
|---|---|---|
| account_id | string, opcional | |
| amounts | object, opcional | |
| chave | string, opcional | |
| competencia | string, opcional | |
| counterparty | object, opcional | |
| created_at | string | obrigatório |
| doc_id | string | obrigatório |
| event_seq | integer | obrigatório |
| history | array de object, opcional | The immutable per-transition records, in order |
| issuer | object, opcional | |
| kind | string | obrigatório |
| obligation_ids | array de string, opcional | |
| provider_refs | object, opcional | |
| rejection | object, opcional | {reason, provider_code, at} — the human text AND the technical code |
| replaced_by | string, opcional | |
| replaces | string, opcional | |
| state | string | obrigatório |
| state_history | array de object | |
| storage_refs | array de object, opcional | |
| tenant | string | obrigatório |
| updated_at | string | obrigatório |
FiscalParty
Issuer or counterparty, as the document names them.
| Campo | Tipo | Detalhe |
|---|---|---|
| account_id | string, opcional | |
| municipio_ibge | string, opcional | |
| name | string, opcional | |
| tax_id | string, opcional | CPF (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.
| Campo | Tipo | Detalhe |
|---|---|---|
| chave | string, opcional | NFS-e chave de acesso (50 characters) |
| provider_code | string, opcional | Provider's technical code (required on REJEITADA) |
| provider_refs | object, opcional | |
| reason | string, opcional | Human-readable reason (required on REJEITADA) |
| replaced_by | string, opcional | |
| storage_refs | array de StorageRef, opcional | |
| to_state | string | obrigatório |
FiscalTransitionResponse
| Campo | Tipo | Detalhe |
|---|---|---|
| account_id | string, opcional | |
| amounts | object, opcional | |
| applied | boolean | obrigatórioFalse when the transition was a no-op |
| chave | string, opcional | |
| competencia | string, opcional | |
| counterparty | object, opcional | |
| created_at | string | obrigatório |
| doc_id | string | obrigatório |
| event_seq | integer | obrigatório |
| history | array de object, opcional | The immutable per-transition records, in order |
| issuer | object, opcional | |
| kind | string | obrigatório |
| noop_reason | string, opcional | ALREADY_IN_STATE (a replay) | NOT_ALLOWED_FROM_STATE |
| obligation_ids | array de string, opcional | |
| provider_refs | object, opcional | |
| rejection | object, opcional | {reason, provider_code, at} — the human text AND the technical code |
| replaced_by | string, opcional | |
| replaces | string, opcional | |
| state | string | obrigatório |
| state_history | array de object | |
| storage_refs | array de object, opcional | |
| tenant | string | obrigatório |
| updated_at | string | obrigatório |
HTTPValidationError
| Campo | Tipo | Detalhe |
|---|---|---|
| detail | array 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.
| Campo | Tipo | Detalhe |
|---|---|---|
| key | string | obrigatórioThe object key in that store — an identifier, never content |
| media_type | "application/xml" | "application/pdf" | obrigatórioWhat the object is |
| sha256 | string | obrigatórioLower-case hex sha256 of the stored bytes |
| size_bytes | integer, opcional | |
| store | string | Who holds the bytes. Only the tenant's backend does today.Padrão "bff" |
ValidationError
| Campo | Tipo | Detalhe |
|---|---|---|
| ctx | object | |
| input | não declarado | |
| loc | array de string ou integer | obrigatório |
| msg | string | obrigatório |
| type | string | obrigatório |