SonaCORE

Referência / Quadra Core API

Accounting Pieces

4 operações em Quadra Core API 0.5.0.

GET/v1/books/{scope_id}/daybook

Livro Diário — every entry set on an account, refused sets included

The Livro Diário of one account: each entry set with **all** its legs, in order, and each refused set as a fact of the period (no legs, its reason). Give ``period`` **or** ``from``+``to``. Every payload carries ``basis``: ``CLOSE_RECORD`` for a closed period, ``LIVE`` otherwise.

Raises: 400: INVALID_QUERY, INVALID_PERIOD, INVALID_CURSOR 404: ACCOUNT_NOT_FOUND (also for estate accounts) 409: CURSOR_STALE (the period's close changed mid-paging)

Parâmetros

NomeTipoDetalhe
scope_idstringpathobrigatório
periodstring, opcionalquery YYYY-MM — answered from the close record when CLOSED
fromstring, opcionalquery Inclusive first accounting day (with 'to'; ≤ 366 days)
tostring, opcionalquery Inclusive last accounting day
cursorstring, opcionalquery Opaque; from the previous page
limitintegerquery Entry sets per page

Respostas

StatusCorpoDetalhe
200DaybookResponseResposta bem-sucedida
422HTTPValidationErrorErro de validação
GET/v1/books/{scope_id}/ledger

Razão — an account's legs per GL node, with running balances

The Razão of one account. The first page carries the per-node summary (opening, period, closing); every page carries running balances.

Raises: 400: INVALID_QUERY, INVALID_PERIOD, INVALID_CURSOR 404: ACCOUNT_NOT_FOUND (also for estate accounts) 409: CURSOR_STALE

Parâmetros

NomeTipoDetalhe
scope_idstringpathobrigatório
periodstring, opcionalquery YYYY-MM — answered from the close record when CLOSED
fromstring, opcionalquery Inclusive first accounting day (with 'to'; ≤ 366 days)
tostring, opcionalquery Inclusive last accounting day
gl_node_idstring, opcionalquery Only this GL node's legs
cursorstring, opcionalquery Opaque; from the previous page
limitintegerquery Legs per page

Respostas

StatusCorpoDetalhe
200LedgerResponseResposta bem-sucedida
422HTTPValidationErrorErro de validação
GET/v1/books/{scope_id}/trial-balance

Balancete — an account's per-node totals as a tree, with the DRE's input

The balancete of one account. For a CLOSED period the rows **are the close record's**, and ``rederivation`` says whether they still re-derive; a disagreement answers 200 with the record's numbers and is logged loudly. ``cross_check`` is the three-way agreement (record, Razão, Diário).

The DRE is not here: its layout is the BFF's. ``by_event_kind`` is its input.

Raises: 400: INVALID_QUERY, INVALID_PERIOD 404: ACCOUNT_NOT_FOUND (also for estate accounts)

Parâmetros

NomeTipoDetalhe
scope_idstringpathobrigatório
periodstring, opcionalquery YYYY-MM — answered from the close record when CLOSED
fromstring, opcionalquery Inclusive first accounting day (with 'to'; ≤ 366 days)
tostring, opcionalquery Inclusive last accounting day

Respostas

StatusCorpoDetalhe
200BooksTrialBalanceResponseResposta bem-sucedida
422HTTPValidationErrorErro de validação
GET/v1/exports/manifest

Export manifest — everything in an account's export box, with content hashes

The completeness manifest for "exportar tudo" (R5): every entry set, refusal, annotation, close record, journal entry, checkpoint and fiscal-document file for one account in the window, each with a content hash, and the epoch floor stated. The BFF assembles the archive; Core never holds document bytes.

⛔ Never truncates: past its item cap it answers 422 MANIFEST_TOO_LARGE.

Raises: 400: INVALID_QUERY 404: ACCOUNT_NOT_FOUND (also for estate accounts) 422: MANIFEST_TOO_LARGE

Parâmetros

NomeTipoDetalhe
scope_idstringqueryobrigatório The account to export
fromstringqueryobrigatório Inclusive first accounting day
tostringqueryobrigatório Inclusive last accounting day (≤ 366 days)

Respostas

StatusCorpoDetalhe
200ExportManifestResponseResposta 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.

AttestationState

Whether the artifact this response carries has been attested, as it is now.

CampoTipoDetalhe
authorizationsintegerActs that authorised a change to the artifact rather than vouching for it (REABERTURA_AUTORIZADA). ⛔ Never counted toward ATTESTED, records or superseded_count: authorising a reopen is not approving the closePadrão 0
current_subject_hashstring, opcionalThe artifact's hash now — what an attestation written now must carry
reasonstring, opcionalWhy the status is not ATTESTED: PENDING_ACCOUNTANT_REVIEW, ARTIFACT_CHANGED_SINCE_ATTESTED, PERIOD_NOT_CLOSED, WINDOW_NOT_A_CLOSED_PERIOD, NO_CORRECTION_RECORDED, SUBJECT_NOT_FOUND
recordsarray de AttestationRecordobrigatórioThe records that bind current_subject_hash, newest first. Empty unless ATTESTED
status"ATTESTED" | "PENDING_ACCOUNTANT_REVIEW" | "SUPERSEDED" | "NOT_ATTESTABLE"obrigatórioATTESTED — at least one record binds the artifact's current hash. PENDING_ACCOUNTANT_REVIEW — attestable, and nobody has. SUPERSEDED — records exist, but the artifact changed after every one of them (a reopened and re-closed period, a document that moved). NOT_ATTESTABLE — there is nothing to sign yet (an open period), and reason says why.
subject_idstringobrigatório
subject_kindstringobrigatório
superseded_countintegerobrigatórioRecords that bind an earlier version

BooksBasis

Which window a piece answered and whether it came from a stored close.

CampoTipoDetalhe
close_seqinteger, opcionalThe close answered from (CLOSE_RECORD only)
closed_atstring, opcionalWhen that close was performed
covered_fromstring, opcionalFirst day the entry model can describe — the opening epoch's day when the window starts before it; null when the window ends before it
epoch_atstring, opcionalThe ledger's opening-epoch instant
floorstring, opcionalSet when the window touches the epoch floor
kindstringobrigatórioCLOSE_RECORD — the numbers are the stored close's, re-derived and compared; LIVE — they can still move. ⚠️ An OPEN or REOPENED period is LIVE, and so is every day range.
livebooleanobrigatórioTrue unless kind is CLOSE_RECORD
periodstring, opcionalYYYY-MM when the request named a period
period_statestring, opcionalOPEN | CLOSED | REOPENED
record_hashstring, opcionalThat close's record_hash
statementstringobrigatórioThe basis in one sentence, for display
window_fromstringobrigatórioFirst accounting day (América/São_Paulo)
window_tostringobrigatórioLast accounting day, inclusive

BooksTrialBalanceResponse

The balancete for one account.

CampoTipoDetalhe
attestationAttestationStateobrigatórioThe CRC attestation of the close this piece is answered from (PERIOD; NOT_ATTESTABLE on a LIVE basis) (contabil-07, catalog R1). Always present: status says whether it is attested, pending review, superseded, or not yet attestable — never a bare null.
basisBooksBasisobrigatório
by_event_kindarray de object, opcionalThis account's legs per (event_kind, layer, asset) — the DRE's input. Revenue for inbound fiscal kinds is booked on the payer's leg, so it never appears in this account's nodes; its event_kind does. The DRE layout is the BFF's.
by_event_kind_agreesboolean, opcionalΣ over kinds == totals
by_event_kind_basisstringobrigatórioRECOMPUTED_FROM_REPRODUCED_LEGS on a CLOSE_RECORD basis (a close stores no per-kind numbers), else LIVE
cross_checkobjectobrigatórioThe three-way agreement: record_totals, razao_totals (GSI1 legs), diario (the base-table legs of every set, with every_set_balanced), agrees.
nodesarray de objectobrigatórioPer (gl_node_id, layer, asset): dr/cr/net_cents (net = dr − cr, the close record's convention), rendered_net_cents (by normal_balance), and the node's name/type/parent_account_id. On a CLOSE_RECORD basis these ARE the record's rows.
rederivationobject, opcionalCLOSE_RECORD only. status agrees | disagrees | not_reproducible_superseded | not_attempted; diffs; late_postings (sets posted after the close, excluded by the projector's own annotation, never by a timestamp); set_membership (digest, or annotation_rule_only for a pre-v3 record). A disagreement answers 200 with the record's numbers, logs at ERROR and counts PieceRederivationMismatch.
scope_idstringobrigatório
totalsobjectobrigatórioPer layer|asset totals. ⚠️ Never zero for one account: the other side of every set sits on another account. Balance is asserted per entry set.
treesarray de objectobrigatórioOne tree per layer|asset, nested by parent_account_id, with subtree_dr/cr and subtree_net_cents rendered by each node's own normal_balance. Orphans and cycles become roots with parent_missing / cycle set.

DaybookResponse

One page of the Livro Diário for one account.

CampoTipoDetalhe
attestationAttestationStateobrigatórioThe CRC attestation of the close this piece is answered from (PERIOD; NOT_ATTESTABLE on a LIVE basis) (contabil-07, catalog R1). Always present: status says whether it is attested, pending review, superseded, or not yet attestable — never a bare null.
basisBooksBasisobrigatório
itemsarray de objectobrigatórioIn GSI1 sort-key order (effective_at, then tx hash) — ⚠️ not strictly accounting_day order when an effective_at carries a numeric offset. kind=ENTRY_SET carries every leg of the set (a counterparty the caller may not see has account_id null and redacted=true), balanced (Σ DR = Σ CR per asset|layer over the base-table legs), matches_header (== the set's layer_totals), annotations, and in_close — false for a set posted into this closed period after its close, null on a LIVE basis. kind=REFUSED_SET is a set the projector refused: no legs, its reason, positioned by the São Paulo day of its confirmation because a refusal has no effective time.
next_cursorstring, opcionalOpaque and bound to this scope, window and basis. A cursor from another question is a 400; a closed-basis cursor whose close changed mid-paging is a 409 CURSOR_STALE. Page until null.
scope_idstringobrigatório
unattributed_refusals_in_windowintegerobrigatórioEstate-wide count of refusals no account could be named for. Carries no identifiers by design; resolving one is an operator task.

ExportManifestResponse

Everything that belongs in one account's export box, each with a content hash.

CampoTipoDetalhe
attestable_hashstringobrigatóriomanifest_hash without the ATTESTATION and CHECKPOINT items — the hash a PIECE attestation binds. Attesting the box never changes it, and neither does a checkpoint sealing the tail
attestationAttestationStateobrigatórioThe CRC attestation of this box as the month's escrituração (PIECE) — NOT_ATTESTABLE unless the window is exactly one CLOSED month (contabil-07, catalog R1). Always present: status says whether it is attested, pending review, superseded, or not yet attestable — never a bare null.
countsobjectobrigatório
floorobjectobrigatórioepoch_at, covered_from, window_starts_before_floor and the statement: nothing before the opening epoch is derivable from entries (RFC-025 D6).
hash_specobjectobrigatórioExactly what each content_hash covers
itemsarray de objectobrigatórioSorted by (kind, id). Kinds: ENTRY_SET, ANNOTATION, REFUSED_SET, PERIOD_CLOSE (every close, superseded ones included), JOURNAL_ENTRY (this account's own), CHECKPOINT, FISCAL_DOCUMENT (one per stored file), ATTESTATION (every CRC attestation of a subject in the box, superseded ones included).
journal_rangeobjectobrigatórioThe journal seq range the window maps to, and uncovered_from_seq when the newest entries are not sealed by a checkpoint yet
kinds_not_availableobjectobrigatórioKinds no ticket has built yet
manifest_hashstringobrigatóriosha256 over the sorted (kind, id, content_hash) triples
manifest_versionintegerobrigatório
periodsarray de objectobrigatórioEvery month the window touches, with its state
scope_idstringobrigatório
sourcesobjectobrigatórioWhere the bytes behind each kind are fetched from
window_fromstringobrigatório
window_tostringobrigatório

HTTPValidationError

CampoTipoDetalhe
detailarray de ValidationError

LedgerResponse

One page of the Razão for one account.

CampoTipoDetalhe
attestationAttestationStateobrigatórioThe CRC attestation of the close this piece is answered from (PERIOD; NOT_ATTESTABLE on a LIVE basis) (contabil-07, catalog R1). Always present: status says whether it is attested, pending review, superseded, or not yet attestable — never a bare null.
basisBooksBasisobrigatório
gl_node_idstring, opcionalThe node filter, when given
itemsarray de objectobrigatórioThis account's legs with running_balance_cents per node|layer|asset. On a CLOSE_RECORD basis a late posting is listed with in_close=false and does not move the running balance.
next_cursorstring, opcionalOpaque; bound like the Diário's. Page until null.
scope_idstringobrigatório
summaryobject, opcionalFirst page only. opening_basis (CLOSE_RECORDS when every month back to the epoch is closed, else LIVE), period_basis, and per node|layer|asset: opening_cents, dr/cr/net_cents for the window (the record's on a CLOSE_RECORD basis), closing_cents. Signed DR-positive (dr − cr); render with normal_balance.

ValidationError

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