Topolo Docs Topolo Platform
Open workspace

Create a bill

Save a draft bill from a supplier. Totals are computed from quantity, unit amount, line discount and tax, never taken from document totals, so the document always foots. The supplier number remains reserved if the bill is later voided.

Outcome

Save a draft bill from a supplier. Totals are computed from quantity, unit amount, line discount and tax, never taken from document totals, so the document always foots. The supplier number remains reserved if the bill is later voided.

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.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.
  • contactId: Exact contact.id from contacts.list/get; a name or email address is not an id.

Request

POST /api/bills

Inspect and test this action. Save the reviewed input as payload.json; supply credential/resource context separately.

Input fields

FieldRequiredMeaningSchema and constraints
issueDateRequiredissue Date{"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"}
linesRequiredComplete 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}}
contactIdOptionalExact contact.id from contacts.list/get; a name or email address is not an id.{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]}
numberOptionalnumber{"anyOf":[{"type":"string","maxLength":60},{"type":"null"}]}
referenceOptionalreference{"anyOf":[{"type":"string","maxLength":200},{"type":"null"}]}
dueDateOptionaldue Date{"anyOf":[{"type":"string","pattern":"^\d{4}-\d{2}-\d{2}$"},{"type":"null"}]}
currencyOptionalISO currency code for the record. Amount units and exchange-rate handling must match it.{"anyOf":[{"type":"string","pattern":"^[A-Z]{3}$"},{"type":"null"}]}
exchangeRateOptionalReviewed 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"}]}
amountsIncludeTaxOptionalWhether invoice or bill line amounts already include tax; inspect the returned net, tax and gross totals.{"type":"boolean"}
notesOptionalnotes{"anyOf":[{"type":"string","maxLength":2000},{"type":"null"}]}

Inspect nested fields and the complete input schema.

Effects

  • Enters a bill from a supplier. Totals come from the lines, so the document always foots.

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 with the returned id and check the total.

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.create --data @payload.json --json
topolo actions plan app_topolo_books.bills.create --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.bills.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.bills.create",
    "input": {
      "contactId": "con_bc225ee51ce54ade8a7ac316eccfae32",
      "issueDate": "2026-09-01",
      "lines": [
        {
          "description": "Fixture services",
          "accountId": "acc_0dfc994d47764901a4de1c2c441cefe9",
          "unitAmountMinor": 2500
        }
      ]
    },
    "resourceType": "workspace",
    "resourceId": "<exact granted workspace id>",
    "confirm": true,
    "detail": true
  }
}

Refused response · auth_error

Input · payload.json:

{
  "contactId": "con_7d31",
  "number": "CF-2026-01",
  "issueDate": "2026-01-31",
  "dueDate": "2026-02-28",
  "lines": [
    {
      "description": "Cloudflare, January",
      "quantity": "1",
      "unitAmountMinor": 4999,
      "accountId": "acc_hosting"
    }
  ]
}

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:

{
  "contactId": "con_bc225ee51ce54ade8a7ac316eccfae32",
  "issueDate": "2026-09-01",
  "lines": [
    {
      "description": "Fixture services",
      "accountId": "acc_0dfc994d47764901a4de1c2c441cefe9",
      "unitAmountMinor": 2500
    }
  ]
}

Captured response · HTTP 201

{
  "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": null,
    "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.488Z",
    "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 201. Call app_topolo_books.bills.get with the returned id and check the total.

Successful response · HTTP 201

Input · payload.json:

{
  "issueDate": "2026-01-20",
  "lines": [
    {
      "description": "Hosting",
      "unitAmountMinor": 4999
    }
  ]
}

Captured response · HTTP 201

{
  "document": {
    "id": "doc_0ae6ed2080b146f591cbc61e249d0158",
    "organization_id": "org_doc-route_muvnp44o11",
    "workspace_id": "ws_doc-route_muvnp44o11",
    "kind": "bill",
    "contact_id": null,
    "number": null,
    "reference": null,
    "issue_date": "2026-01-20",
    "due_date": null,
    "period_key": "2026-01",
    "currency": "USD",
    "exchange_rate": null,
    "subtotal_minor": 4999,
    "tax_minor": 0,
    "total_minor": 4999,
    "base_total_minor": 4999,
    "paid_minor": 0,
    "status": "draft",
    "notes": null,
    "posted_event_id": null,
    "source": "manual",
    "source_document_id": null,
    "created_at": "2026-10-05T19:42:14.620Z",
    "updated_at": "2026-10-05T19:42:14.620Z",
    "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_13c7b7079f34496ba2449876316a4ec5",
      "organization_id": "org_doc-route_muvnp44o11",
      "workspace_id": "ws_doc-route_muvnp44o11",
      "document_id": "doc_0ae6ed2080b146f591cbc61e249d0158",
      "line_no": 1,
      "description": "Hosting",
      "quantity": "1",
      "unit_amount_minor": 4999,
      "account_id": null,
      "tax_code": null,
      "tax_minor": 0,
      "line_total_minor": 4999,
      "created_at": "2026-10-05T19:42:14.620Z",
      "updated_at": "2026-10-05T19:42:14.620Z",
      "discount_percent": "0",
      "discount_minor": 0
    }
  ]
}

HTTP 201. Call app_topolo_books.bills.get with the returned id and check the total.

Successful response · HTTP 201

Input · payload.json:

{
  "contactId": "con_b3da013894b9468593b2db7e2eef7edd",
  "number": "SUP-2",
  "issueDate": "2026-03-02",
  "lines": [
    {
      "description": "Supply",
      "unitAmountMinor": 750
    }
  ]
}

Captured response · HTTP 201

{
  "document": {
    "id": "doc_0812a78c9a6f484ca1114dc19582b02e",
    "organization_id": "org_doc-lifecycle-route_muvnp46b12",
    "workspace_id": "ws_doc-lifecycle-route_muvnp46b12",
    "kind": "bill",
    "contact_id": "con_b3da013894b9468593b2db7e2eef7edd",
    "number": "SUP-2",
    "reference": null,
    "issue_date": "2026-03-02",
    "due_date": null,
    "period_key": "2026-03",
    "currency": "USD",
    "exchange_rate": null,
    "subtotal_minor": 750,
    "tax_minor": 0,
    "total_minor": 750,
    "base_total_minor": 750,
    "paid_minor": 0,
    "status": "draft",
    "notes": null,
    "posted_event_id": null,
    "source": "manual",
    "source_document_id": null,
    "created_at": "2026-10-05T19:42:14.652Z",
    "updated_at": "2026-10-05T19:42:14.652Z",
    "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_6131f44bf084483e8108efc2a8c641b8",
      "organization_id": "org_doc-lifecycle-route_muvnp46b12",
      "workspace_id": "ws_doc-lifecycle-route_muvnp46b12",
      "document_id": "doc_0812a78c9a6f484ca1114dc19582b02e",
      "line_no": 1,
      "description": "Supply",
      "quantity": "1",
      "unit_amount_minor": 750,
      "account_id": null,
      "tax_code": null,
      "tax_minor": 0,
      "line_total_minor": 750,
      "created_at": "2026-10-05T19:42:14.652Z",
      "updated_at": "2026-10-05T19:42:14.652Z",
      "discount_percent": "0",
      "discount_minor": 0
    }
  ]
}

HTTP 201. Call app_topolo_books.bills.get with the returned id and check the total.

Verify the result

  • Call app_topolo_books.bills.get with the returned id and check the total.

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.

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

Void the bill; it stays readable and its supplier number remains reserved.

  • Get a bill: Read one bill with its lines and the payments against it.
  • Record a payment: Record money paid against a bill. The paid total is the sum of the payments, and the document becomes paid once they cover it.
  • 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.
  • Void a bill: Void a bill while keeping its supplier number and history readable. Refused while payments are recorded against it.

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.