Outcome
Change a draft bill. Sending lines replaces them all and recomputes discounts and totals. Financial details are locked after approval.
Before you start
- Verify the intended environment, authenticated identity and specifically approved organization context.
- The published application permission is bills: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.bills.update --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.
- documentId: Exact document.id from invoices.list/get or bills.list/get, as appropriate to this action; the displayed invoice number is distinct.
- contactId: Exact contact.id from contacts.list/get; a name or email address is not an id.
Request
PATCH /api/bills/{documentId}
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 |
|---|---|---|---|
documentId | Required | Exact document.id from invoices.list/get or bills.list/get, as appropriate to this action; the displayed invoice number is distinct. | {"type":"string","minLength":1} |
issueDate | Optional | issue Date | {"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"} |
lines | Optional | 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":1,"maxItems":500,"type":"array","items":{"type":"object","properties":{"description":{"type":"string","minLength":1,"maxLength":500},"quantity":{"anyOf":[{"type":"string","pattern":"^-?\d{1,12}(\.\d{1,6})?$"},{"type":"number"}]},"unitAmountMinor":{"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991},"discountPercent":{"anyOf":[{"type":"string","pattern":"^(?:100(?:\.0{1,4})?|(?:\d{1,2})(?:\.\d{1,4})?)$"},{"type":"number","minimum":0,"maximum":100,"multipleOf":0.0001}]},"accountId":{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]},"taxCode":{"anyOf":[{"type":"string","maxLength":60},{"type":"null"}]}},"required":["description"],"additionalProperties":false}} |
contactId | Optional | Exact contact.id from contacts.list/get; a name or email address is not an id. | {"anyOf":[{"type":"string","minLength":1},{"type":"null"}]} |
number | Optional | number | {"anyOf":[{"type":"string","maxLength":60},{"type":"null"}]} |
reference | Optional | reference | {"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]} |
dueDate | Optional | due Date | {"anyOf":[{"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"},{"type":"null"}]} |
currency | Optional | ISO currency code for the record. Amount units and exchange-rate handling must match it. | {"anyOf":[{"type":"string","pattern":"^[A-Z]{3}$"},{"type":"null"}]} |
exchangeRate | Optional | Reviewed exchange rate for the supplied currencies/date; a fixture rate is not a live market quote. | {"anyOf":[{"type":"string","pattern":"^-?\d{1,12}(\.\d{1,6})?$"},{"type":"null"}]} |
amountsIncludeTax | Optional | Whether invoice or bill line amounts already include tax; inspect the returned net, tax and gross totals. | {"type":"boolean"} |
notes | Optional | notes | {"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}]} |
Inspect nested fields and the complete input schema.
Effects
- Changes a draft bill. Sending lines replaces every line and recomputes the totals; approved financial details are locked.
Interpret the response
Read $.document.id for the returned bill identifier. Empty collections and nullable fields do not discover a target.
Call app_topolo_books.bills.get and compare the totals.
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.bills.update --data @payload.json --json
topolo actions plan app_topolo_books.bills.update --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.bills.update --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.bills.update",
"input": {
"documentId": "doc_ed6a61b948484d9c806b03ebfdf279ec",
"reference": "FIXTURE-PO"
},
"resourceType": "workspace",
"resourceId": "<exact granted workspace id>",
"confirm": true,
"detail": true
}
}
Refused response · auth_error
Input · payload.json:
{
"documentId": "doc_11bc",
"dueDate": "2026-03-15"
}
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 200
Input · payload.json:
{
"documentId": "doc_ed6a61b948484d9c806b03ebfdf279ec",
"reference": "FIXTURE-PO"
}
Captured response · HTTP 200
{
"document": {
"id": "doc_ed6a61b948484d9c806b03ebfdf279ec",
"organization_id": "org_documentation-bill_muvnpncj3",
"workspace_id": "ws_documentation-bill_muvnpncj3",
"kind": "bill",
"contact_id": "con_bc225ee51ce54ade8a7ac316eccfae32",
"number": null,
"reference": "FIXTURE-PO",
"issue_date": "2026-09-01",
"due_date": null,
"period_key": "2026-09",
"currency": "GBP",
"exchange_rate": null,
"subtotal_minor": 2500,
"tax_minor": 0,
"total_minor": 2500,
"base_total_minor": 2500,
"paid_minor": 0,
"status": "draft",
"notes": null,
"posted_event_id": null,
"source": "manual",
"source_document_id": null,
"created_at": "2026-10-05T19:42:39.488Z",
"updated_at": "2026-10-05T19:42:39.495Z",
"sequence_no": null,
"approved_at": null,
"sent_at": null,
"amounts_include_tax": 0,
"design_project_id": null,
"design_export_id": null,
"design_rendered_at": null,
"brand_kit_id": null,
"brand_version_id": null,
"written_off_minor": 0
},
"lines": [
{
"id": "dln_648b9f796e23455a896b91d282ef1cd3",
"organization_id": "org_documentation-bill_muvnpncj3",
"workspace_id": "ws_documentation-bill_muvnpncj3",
"document_id": "doc_ed6a61b948484d9c806b03ebfdf279ec",
"line_no": 1,
"description": "Fixture services",
"quantity": "1",
"unit_amount_minor": 2500,
"account_id": "acc_0dfc994d47764901a4de1c2c441cefe9",
"tax_code": null,
"tax_minor": 0,
"line_total_minor": 2500,
"created_at": "2026-10-05T19:42:39.488Z",
"updated_at": "2026-10-05T19:42:39.488Z",
"discount_percent": "0",
"discount_minor": 0
}
]
}
HTTP 200. Call app_topolo_books.bills.get and compare the totals.
Refused response · document_not_found
Input · payload.json:
{
"documentId": "doc_4e67b9476d1b417ba15e145cb845be2c",
"reference": "x"
}
Captured response · HTTP 404
{
"error": "document_not_found",
"message": "Bill doc_4e67b9476d1b417ba15e145cb845be2c does not exist in this workspace"
}
HTTP 404. SDK error code document_not_found. Use invoices.list/get or bills.list/get in the same workspace and retain document.id. The invoice number is not its id.
Verify the result
- Call app_topolo_books.bills.get and compare the totals.
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.document_not_found(HTTP 404): Use invoices.list/get or bills.list/get in the same workspace and retain document.id. The invoice number is not its id.
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
Read bills.get before changing anything, then send the previous values back.
Related actions
- List bills: List bills newest first. Filter by status, contact or issue date, search the number, reference and notes, and sort by issue date, due date, number, total or status. The response carries the outstanding total for the filtered set.
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.