Topolo Docs Topolo Platform
Open workspace

Match a bank line to a document

Record the line as a payment against the invoice (money in) or bill (money out) it settled, dated the line's date and posted to the ledger against the bank account, and mark the line matched. amountMinor defaults to the smaller of the line and what is outstanding. Refused when the direction or currency does not fit.

Outcome

Record the line as a payment against the invoice (money in) or bill (money out) it settled, dated the line's date and posted to the ledger against the bank account, and mark the line matched. amountMinor defaults to the smaller of the line and what is outstanding. Refused when the direction or currency does not fit.

Before you start

  • Verify the intended environment, authenticated identity and specifically approved organization context.
  • The published application permission is banking: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.bank.lines.match --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.
  • lineId: Exact bank line.id from bank.lines.list; inspect its current matching state before mutation.
  • documentId: Exact document.id from invoices.list/get or bills.list/get, as appropriate to this action; the displayed invoice number is distinct.

Request

POST /api/bank/lines/{lineId}/match

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

Input fields

FieldRequiredMeaningSchema and constraints
lineIdRequiredExact bank line.id from bank.lines.list; inspect its current matching state before mutation.{"type":"string","minLength":1}
documentIdRequiredExact 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}
amountMinorOptionalCurrency minor units as a safe integer, not a decimal money string. Follow this action’s sign and minimum constraints.{"type":"integer","exclusiveMinimum":0,"maximum":9007199254740991}

Inspect nested fields and the complete input schema.

Effects

  • Records a payment on the document dated the line's date and carrying the line id, posts it to the ledger against the bank account (the document module's own posting), and marks the line matched to the document and payment.

Interpret the response

Read $.line.id for the returned bank_line identifier. Empty collections and nullable fields do not discover a target.

Call app_topolo_books.invoices.get or app_topolo_books.bills.get and confirm the payment and the new paid amount.

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.bank.lines.match --data @payload.json --json
topolo actions plan app_topolo_books.bank.lines.match --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.bank.lines.match --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.bank.lines.match",
    "input": {
      "lineId": "bl_np6mi3_2",
      "documentId": "doc_cb5d353fca8b46e886d4ab99dd419ec4"
    },
    "resourceType": "workspace",
    "resourceId": "<exact granted workspace id>",
    "confirm": true,
    "detail": true
  }
}

Refused response · auth_error

Input · payload.json:

{
  "lineId": "bl_9c1",
  "documentId": "doc_inv_1042"
}

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:

{
  "lineId": "bl_np6mi3_2",
  "documentId": "doc_cb5d353fca8b46e886d4ab99dd419ec4"
}

Captured response · HTTP 201

{
  "line": {
    "id": "bl_np6mi3_2",
    "organization_id": "org_rec_muvnp6mi3",
    "workspace_id": "ws_rec_muvnp6mi3",
    "bank_account_id": "bk_main_np6mi3",
    "source": "statement",
    "provider_transaction_id": "tx-bl_np6mi3_2",
    "posted_on": "2026-06-28",
    "period_key": "2026-06",
    "amount_minor": 80000,
    "currency": "GBP",
    "description": "FPS ACME LTD INV-7",
    "counterparty": null,
    "memo": null,
    "kind": null,
    "provider_status": null,
    "fingerprint": "fp-bl_np6mi3_2",
    "match_status": "matched",
    "matched_event_id": "je_0fd3efe46a65401e917c0fb5ea5dfd0b",
    "raw": null,
    "imported_at": "2026-06-30T00:00:00Z",
    "updated_at": "2026-10-05T19:42:17.843Z",
    "duplicate_of": null,
    "coded_account_id": null,
    "matched_document_id": "doc_cb5d353fca8b46e886d4ab99dd419ec4",
    "matched_payment_id": "pay_19c6d92f6f8b438caeb280c10ec9b4c9",
    "reconciled_at": "2026-10-05T19:42:17.843Z",
    "reconciled_by": "usr_test",
    "coded_by_rule_id": null,
    "xero_coding": null
  },
  "document": {
    "id": "doc_cb5d353fca8b46e886d4ab99dd419ec4",
    "organization_id": "org_rec_muvnp6mi3",
    "workspace_id": "ws_rec_muvnp6mi3",
    "kind": "invoice",
    "contact_id": "con_ad7e66c471824337b7aca34a2393f92a",
    "number": "INV-7",
    "reference": null,
    "issue_date": "2026-06-01",
    "due_date": null,
    "period_key": "2026-06",
    "currency": "GBP",
    "exchange_rate": null,
    "subtotal_minor": 80000,
    "tax_minor": 0,
    "total_minor": 80000,
    "base_total_minor": 80000,
    "paid_minor": 80000,
    "status": "paid",
    "notes": null,
    "posted_event_id": null,
    "source": "manual",
    "source_document_id": null,
    "created_at": "2026-10-05T19:42:17.815Z",
    "updated_at": "2026-10-05T19:42:17.837Z",
    "sequence_no": null,
    "approved_at": "2026-10-05T19:42:17.815Z",
    "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
  },
  "paymentId": "pay_19c6d92f6f8b438caeb280c10ec9b4c9",
  "journalId": "je_0fd3efe46a65401e917c0fb5ea5dfd0b"
}

HTTP 201. Call app_topolo_books.invoices.get or app_topolo_books.bills.get and confirm the payment and the new paid amount.

Refused response · document_not_found

Input · payload.json:

{
  "lineId": "bl_np6pa4_1",
  "documentId": "x"
}

Captured response · HTTP 404

{
  "error": "document_not_found",
  "message": "Document x 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.invoices.get or app_topolo_books.bills.get and confirm the payment and the new paid amount.

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

The payment is the record of money received or paid. Correct it through the document, not by unmatching the line.

  • List bank lines: List statement lines, filtered by account, match status or date, searched across description, counterparty, memo and the bank's transaction id, and sorted by posted date, amount, description or match status. Newest first unless you say otherwise; linkedOnly restricts them to accounts linked to a ledger account.
  • Suggest how to reconcile a bank line: For one unmatched statement line: open invoices (money in) or bills (money out) it could be settling, scored by amount, a number or contact named in the description and date; the opposite line in another of our accounts that makes it a transfer; and the accounts lines like it were coded to before, with how often. Best first.
  • Get aged receivables: What customers still owe at a date, by customer and currency, in buckets of how overdue it is (default 30,60,90 days past the due date; basis issue ages from the issue date instead). Outstanding is worked out at the date, so payments after it do not count. Includes every open document with its bucket for drill-down.
  • List bank accounts: List the bank accounts reported by connected banks, with cached balances and the ledger account each maps to. linkedOnly returns just the accounts pointed at a ledger account.

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.