Outcome
Post a balanced manual journal to the ledger. Optionally schedule its exact reversal for the first day of a later month with autoReverseOn. Refused with unbalanced_journal, period_locked, account_not_found or account_archived; an idempotencyKey replays the same event. Every line is signed base-currency minor units: positive debit, negative credit.
Before you start
- Verify the intended environment, authenticated identity and specifically approved organization context.
- The published application permission is journals:write. Discover the exact granted canonical Books workspace and bind it separately from action input.
- Approve the actual mutation, accounting inputs and any provider/recipient effects before CLI --confirm or MCP confirm:true. Fixture identifiers and simulated provider responses authorize no live operation.
Discover the target
topolo whoami --json
topolo actions get app_topolo_books.journals.create --detail --json
topolo resources topolo-books --json
topolo workspaces list topolo-books --json
- Set BOOKS_WORKSPACE_ID to the exact granted workspace returned by discovery.
- sourceDocumentId: Resolve this exact identifier through the related published reads for the same organization and workspace; never infer it from a name.
Request
POST /api/journals
Inspect and test this action. Save the reviewed input as payload.json; supply credential/resource context separately.
Input fields
| Field | Required | Meaning | Schema and constraints |
|---|---|---|---|
postedOn | Required | posted On | {"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"} |
description | Required | description | {"type":"string","minLength":1,"maxLength":500} |
reference | Optional | reference | {"anyOf":[{"type":"string","maxLength":100},{"type":"null"}]} |
notes | Optional | notes | {"anyOf":[{"type":"string","maxLength":4000},{"type":"null"}]} |
journalType | Optional | journal Type | {"type":"string","maxLength":40} |
idempotencyKey | Optional | Retained key for one intended operation. Reusing it for different attachment bytes or send details can conflict. | {"type":"string","minLength":1,"maxLength":200} |
sourceApp | Optional | source App | {"type":"string","maxLength":80} |
sourceDocumentType | Optional | source Document Type | {"anyOf":[{"type":"string","maxLength":80},{"type":"null"}]} |
sourceDocumentId | Optional | source Document Id | {"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]} |
autoReverseOn | Optional | auto Reverse On | {"anyOf":[{"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"},{"type":"null"}]} |
overrideSoftLock | Optional | Explicit override of a soft accounting lock; inspect the lock and obtain authority before posting. | {"type":"boolean"} |
lines | Required | Complete structured lines in the published nested schema. Journal lines use signed minor units and must balance; invoice/bill lines have their own pricing and tax shape. | {"minItems":2,"maxItems":500,"type":"array","items":{"type":"object","properties":{"accountId":{"type":"string","minLength":1},"amountMinor":{"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},"documentCurrency":{"type":"string","pattern":"^[A-Z]{3}$"},"documentAmountMinor":{"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},"fxRate":{"type":"string","pattern":"^\d+(\.\d+)?$"},"taxRateId":{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]},"contactId":{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]},"dimensions":{"anyOf":[{"type":"object","propertyNames":{"type":"string"},"additionalProperties":{"type":"string"}},{"type":"null"}]},"memo":{"anyOf":[{"type":"string","maxLength":500},{"type":"null"}]}},"required":["accountId","amountMinor"],"additionalProperties":false}} |
Inspect nested fields and the complete input schema.
Effects
- Appends one immutable event to the ledger hash chain and updates the balance projection. Nothing is ever edited or deleted.
- Lines are signed base-currency minor units: a positive amount is a debit, a negative amount is a credit, and they must sum to zero.
- When autoReverseOn is provided, the pending schedule is created atomically with the journal and the hourly worker posts the exact opposite entry on that date.
Interpret the response
Read $.journal.id for the returned journal identifier. Empty collections and nullable fields do not discover a target.
Call app_topolo_books.ledger.trial_balance.get and confirm balanced is true, or read the event back with app_topolo_books.journals.get.
Inspect the success schema. CLI/MCP add their own transport envelope; CLI --detail requests the full result.
Worked examples
Actual Books route handlers and the exported Worker were exercised against five local SQLite D1 concern databases with all committed migrations, the real posting Durable Object and local R2. Route captures use synthetic verified Auth; Worker captures use synthetic Auth transports. Nexus, Brand, Notify, Pay, Mercury and Xero responses are explicitly simulated at the provider transport boundary. Captures prove local request/response behavior and canonical SDK projection, not live bank access, payment movement, email delivery, provider eligibility, tax compliance, encrypted custody, scheduled execution, deployment or production completion. Fixture identities, credentials, addresses and records authorize no live operation.
Run a reviewed request
Save the input from the selected worked example as payload.json. Validate and inspect the plan before calling the action; refused examples demonstrate errors and are not instructions to execute.
CLI:
topolo actions validate app_topolo_books.journals.create --data @payload.json --json
topolo actions plan app_topolo_books.journals.create --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.journals.create --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --confirm --detail --json
MCP tool and arguments for the first successful example:
{
"tool": "topolo_call_action",
"arguments": {
"actionId": "app_topolo_books.journals.create",
"input": {
"postedOn": "2026-09-02",
"description": "Capital",
"lines": [
{
"accountId": "acc_873bdb78fad44749b99b4acacb376541",
"amountMinor": 500000
},
{
"accountId": "acc_ed1238b8fa864827ac904306ca7c8f85",
"amountMinor": -500000
}
]
},
"resourceType": "workspace",
"resourceId": "<exact granted workspace id>",
"confirm": true,
"detail": true
}
}
Refused response · auth_error
Input · payload.json:
{
"postedOn": "2026-01-15",
"description": "Hosting invoice",
"reference": "INV-1042",
"idempotencyKey": "hosting-2026-01",
"autoReverseOn": "2026-02-01",
"lines": [
{
"accountId": "acc_hosting_expense",
"amountMinor": 12000,
"memo": "January hosting"
},
{
"accountId": "acc_accounts_payable",
"amountMinor": -12000
}
]
}
Captured response · HTTP 401
{
"error": "API key validation failed"
}
HTTP 401. SDK error code auth_error. Authenticate in the intended organization again. Verify whoami and the exact Books application/workspace binding before retrying; do not switch identity to work around a refusal.
Successful response · HTTP 201
Input · payload.json:
{
"postedOn": "2026-09-02",
"description": "Capital",
"lines": [
{
"accountId": "acc_873bdb78fad44749b99b4acacb376541",
"amountMinor": 500000
},
{
"accountId": "acc_ed1238b8fa864827ac904306ca7c8f85",
"amountMinor": -500000
}
]
}
Captured response · HTTP 201
{
"journal": {
"id": "je_54b47a66232d441398dfd326d14f1bd5",
"organization_id": "org_route_muvnp2sb19",
"workspace_id": "ws_route_muvnp2sb19",
"sequence": 1,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"event_type": "journal_posted",
"journal_type": "manual",
"description": "Capital",
"reference": null,
"source_app": "topolo-books",
"source_document_type": null,
"source_document_id": null,
"actor_type": "topolo_agent",
"actor_id": "usr_test",
"autonomy_level": null,
"correlation_id": "req_route",
"idempotency_key": "je_54b47a66232d441398dfd326d14f1bd5",
"reverses_event_id": null,
"reversed_by_event_id": null,
"total_debit_minor": 500000,
"total_credit_minor": 500000,
"line_count": 2,
"previous_hash": "",
"hash": "268c7529e04236346f5c740e4b6bf9467f1055b21608c339fe691bbf1e92d67c",
"created_at": "2026-10-05T19:42:12.861Z",
"notes": null
},
"lines": [
{
"id": "jl_c0b04430484148669ca26698e0ca35a4",
"organization_id": "org_route_muvnp2sb19",
"workspace_id": "ws_route_muvnp2sb19",
"event_id": "je_54b47a66232d441398dfd326d14f1bd5",
"sequence": 1,
"line_no": 1,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"account_id": "acc_873bdb78fad44749b99b4acacb376541",
"amount_minor": 500000,
"currency": "GBP",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
},
{
"id": "jl_b6b786a4ef1c471d81c0525ab3658974",
"organization_id": "org_route_muvnp2sb19",
"workspace_id": "ws_route_muvnp2sb19",
"event_id": "je_54b47a66232d441398dfd326d14f1bd5",
"sequence": 1,
"line_no": 2,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"account_id": "acc_ed1238b8fa864827ac904306ca7c8f85",
"amount_minor": -500000,
"currency": "GBP",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
}
],
"autoReversal": null
}
HTTP 201. Call app_topolo_books.ledger.trial_balance.get and confirm balanced is true, or read the event back with app_topolo_books.journals.get.
Refused response · unbalanced_journal
Input · payload.json:
{
"postedOn": "2026-09-02",
"description": "Bad",
"lines": [
{
"accountId": "acc_873bdb78fad44749b99b4acacb376541",
"amountMinor": 5
},
{
"accountId": "acc_ed1238b8fa864827ac904306ca7c8f85",
"amountMinor": -6
}
]
}
Captured response · HTTP 400
{
"error": "unbalanced_journal",
"message": "Debits 5 do not equal credits 6 (difference -1 minor units)",
"details": {
"debitsMinor": 5,
"creditsMinor": 6
}
}
HTTP 400. SDK error code unbalanced_journal. Reconcile the signed base-currency integer minor-unit lines so debits equal credits. Correct the source accounting allocation before posting; never invent a difference line.
Refused response · amount_overflow
Input · payload.json:
{
"postedOn": "2026-09-02",
"description": "Huge",
"lines": [
{
"accountId": "acc_7375e6f25c8c4e398323f3d33d9e19c3",
"amountMinor": 9007199254740991
},
{
"accountId": "acc_153a55aea52e4396afd67ea924e91ebe",
"amountMinor": 1
},
{
"accountId": "acc_f0aaeb5c1204494c90aeb2538e9ca83c",
"amountMinor": -1
},
{
"accountId": "acc_5a1b782f57174ca2948b3f178c27c3ba",
"amountMinor": -9007199254740991
}
]
}
Captured response · HTTP 400
{
"error": "amount_overflow",
"message": "Sum exceeds the safe integer range"
}
HTTP 400. SDK error code amount_overflow. Keep all source and summed money amounts within JavaScript safe integer bounds. Correct the actual units; never scale or split entries solely to bypass validation.
Successful response · HTTP 201
Input · payload.json:
{
"postedOn": "2026-09-30",
"description": "Month-end accrual",
"autoReverseOn": "2026-10-01",
"lines": [
{
"accountId": "acc_6f83d8a31a174adf8a4453dce79d9aa6",
"amountMinor": 25000
},
{
"accountId": "acc_97ac5a44d76640f2b1fd07f0a77a69c6",
"amountMinor": -25000
}
]
}
Captured response · HTTP 201
{
"journal": {
"id": "je_b9f2faa9823d47cb8a4d9668747d10bf",
"organization_id": "org_auto-route_muvnp2v321",
"workspace_id": "ws_auto-route_muvnp2v321",
"sequence": 1,
"period_key": "2026-09",
"posted_on": "2026-09-30",
"event_type": "journal_posted",
"journal_type": "manual",
"description": "Month-end accrual",
"reference": null,
"source_app": "topolo-books",
"source_document_type": null,
"source_document_id": null,
"actor_type": "topolo_agent",
"actor_id": "usr_test",
"autonomy_level": null,
"correlation_id": "req_route",
"idempotency_key": "je_b9f2faa9823d47cb8a4d9668747d10bf",
"reverses_event_id": null,
"reversed_by_event_id": null,
"total_debit_minor": 25000,
"total_credit_minor": 25000,
"line_count": 2,
"previous_hash": "",
"hash": "4169f0e20674b49d04fbfcf119cea49097baa7cd7cd7f06d498c6c1273c67141",
"created_at": "2026-10-05T19:42:12.943Z",
"notes": null
},
"lines": [
{
"id": "jl_e7e0fdc732dd4d47a38306aff1f3acaf",
"organization_id": "org_auto-route_muvnp2v321",
"workspace_id": "ws_auto-route_muvnp2v321",
"event_id": "je_b9f2faa9823d47cb8a4d9668747d10bf",
"sequence": 1,
"line_no": 1,
"period_key": "2026-09",
"posted_on": "2026-09-30",
"account_id": "acc_6f83d8a31a174adf8a4453dce79d9aa6",
"amount_minor": 25000,
"currency": "GBP",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
},
{
"id": "jl_7dace215843e4cc9a6625af113387874",
"organization_id": "org_auto-route_muvnp2v321",
"workspace_id": "ws_auto-route_muvnp2v321",
"event_id": "je_b9f2faa9823d47cb8a4d9668747d10bf",
"sequence": 1,
"line_no": 2,
"period_key": "2026-09",
"posted_on": "2026-09-30",
"account_id": "acc_97ac5a44d76640f2b1fd07f0a77a69c6",
"amount_minor": -25000,
"currency": "GBP",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
}
],
"autoReversal": {
"id": "revsch_75496a73bd0b45179fd6b55cb9bc821b",
"organization_id": "org_auto-route_muvnp2v321",
"workspace_id": "ws_auto-route_muvnp2v321",
"journal_event_id": "je_b9f2faa9823d47cb8a4d9668747d10bf",
"reverse_on": "2026-10-01",
"status": "pending",
"reversal_event_id": null,
"attempts": 0,
"last_error": null,
"created_at": "2026-10-05T19:42:12.943Z",
"updated_at": "2026-10-05T19:42:12.943Z",
"cancelled_at": null,
"completed_at": null
}
}
HTTP 201. Call app_topolo_books.ledger.trial_balance.get and confirm balanced is true, or read the event back with app_topolo_books.journals.get.
Successful response · HTTP 201
Input · payload.json:
{
"postedOn": "2026-09-02",
"description": "Capital",
"lines": [
{
"accountId": "acc_010010bba13048b381a3f071b205786a",
"amountMinor": 250000
},
{
"accountId": "acc_73432ec2c37f467fa8757daf328ec791",
"amountMinor": -250000
}
]
}
Captured response · HTTP 201
{
"journal": {
"id": "je_4a4400bf835e4d3eba09772ca433c898",
"organization_id": "org_e2e_muvnp7qn2",
"workspace_id": "ws_e2e_muvnp7qn2",
"sequence": 1,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"event_type": "journal_posted",
"journal_type": "manual",
"description": "Capital",
"reference": null,
"source_app": "topolo-books",
"source_document_type": null,
"source_document_id": null,
"actor_type": "topolo_agent",
"actor_id": "usr_1",
"autonomy_level": null,
"correlation_id": null,
"idempotency_key": "je_4a4400bf835e4d3eba09772ca433c898",
"reverses_event_id": null,
"reversed_by_event_id": null,
"total_debit_minor": 250000,
"total_credit_minor": 250000,
"line_count": 2,
"previous_hash": "",
"hash": "9aa6dc24abc6ead5d78dc87a364f0dfd84c9ae23fdafbe5a4853c6a1a1afd1bb",
"created_at": "2026-10-05T19:42:19.273Z",
"notes": null
},
"lines": [
{
"id": "jl_0a91405d1b4b40e5a06608738b1e25b2",
"organization_id": "org_e2e_muvnp7qn2",
"workspace_id": "ws_e2e_muvnp7qn2",
"event_id": "je_4a4400bf835e4d3eba09772ca433c898",
"sequence": 1,
"line_no": 1,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"account_id": "acc_010010bba13048b381a3f071b205786a",
"amount_minor": 250000,
"currency": "USD",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
},
{
"id": "jl_fe29ab6228534865a14f69fd2e2edacc",
"organization_id": "org_e2e_muvnp7qn2",
"workspace_id": "ws_e2e_muvnp7qn2",
"event_id": "je_4a4400bf835e4d3eba09772ca433c898",
"sequence": 1,
"line_no": 2,
"period_key": "2026-09",
"posted_on": "2026-09-02",
"account_id": "acc_73432ec2c37f467fa8757daf328ec791",
"amount_minor": -250000,
"currency": "USD",
"document_currency": null,
"document_amount_minor": null,
"fx_rate": null,
"tax_rate_id": null,
"contact_id": null,
"dimensions": null,
"memo": null
}
],
"autoReversal": null
}
HTTP 201. Call app_topolo_books.ledger.trial_balance.get and confirm balanced is true, or read the event back with app_topolo_books.journals.get.
Verify the result
- Call app_topolo_books.ledger.trial_balance.get and confirm balanced is true, or read the event back with app_topolo_books.journals.get.
Errors and recovery
auth_error(HTTP 401): Authenticate in the intended organization again. Verify whoami and the exact Books application/workspace binding before retrying; do not switch identity to work around a refusal.unbalanced_journal(HTTP 400): Reconcile the signed base-currency integer minor-unit lines so debits equal credits. Correct the source accounting allocation before posting; never invent a difference line.amount_overflow(HTTP 400): Keep all source and summed money amounts within JavaScript safe integer bounds. Correct the actual units; never scale or split entries solely to bypass validation.
These are observed local refusals. Shared authentication, schema validation and resource authorization can also refuse before the route. Preserve the actual error, details and request id.
Recovery boundary
Reverse the journal: the same lines are posted negated as a new event. Corrections are reversals, never edits.
Related actions
- Get journal: Read one journal event with every line, its account and its debit or credit, which is what reconciles against the ledger.
- List automatic reversals: List the workspace journal reversal schedules, optionally filtered to pending, completed or cancelled.
- Get trial balance: Every account holding a balance at the date, each on one side only: debitMinor carries a debit balance, creditMinor a credit balance, and the other is zero. Accounts that net to nothing are left out. totalDebitMinor and totalCreditMinor are the sums of those balances and must agree, which is what balanced reports. These are balances, not turnover: they do not add up everything ever posted to an account, which would count both sides of every entry and count an expense again when a year-end close reverses it.
- List journals: List posted journal events, filtered by date range or period, searched across description, reference and journal type, and sorted by sequence, posted date, description or amount. Newest first unless you say otherwise.
- Reverse a journal: Post the reversal of a journal: the same lines negated, dated as requested (default the original date). A journal can be reversed once; corrections are reversals, never edits.
Evidence
Actual Books route handlers and the exported Worker were exercised against five local SQLite D1 concern databases with all committed migrations, the real posting Durable Object and local R2. Route captures use synthetic verified Auth; Worker captures use synthetic Auth transports. Nexus, Brand, Notify, Pay, Mercury and Xero responses are explicitly simulated at the provider transport boundary. Captures prove local request/response behavior and canonical SDK projection, not live bank access, payment movement, email delivery, provider eligibility, tax compliance, encrypted custody, scheduled execution, deployment or production completion. Fixture identities, credentials, addresses and records authorize no live operation.