Outcome
Run the active rules over unmatched lines in linked bank accounts (optionally one bank account or a list of lines). The first rule that fits a line codes it: one journal between the bank's ledger account and the rule's account, the line marked matched with coded_by_rule_id set, the rule's times_applied advanced. dryRun true lists what would be coded without posting. Lines no rule fits are counted in unmatched; a line a rule fits but cannot code (locked period, archived account) is listed in skipped with the refusal code.
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.rules.apply --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.
- bankAccountId: Exact local bank account.id from bank.accounts.list; a provider account identifier is separate.
- lineIds: Complete, reviewed list of bank line ids for this operation; discover each before executing a bulk mutation.
Request
POST /api/bank/rules/apply
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 |
|---|---|---|---|
bankAccountId | Optional | Exact local bank account.id from bank.accounts.list; a provider account identifier is separate. | {"anyOf":[{"type":"string","minLength":1},{"type":"null"}]} |
lineIds | Optional | Complete, reviewed list of bank line ids for this operation; discover each before executing a bulk mutation. | {"maxItems":500,"type":"array","items":{"type":"string","minLength":1}} |
dryRun | Optional | Preview the operation when true; inspect the actual result before approving a state-changing run. | {"type":"boolean"} |
Inspect nested fields and the complete input schema.
Effects
- Posts one bank-coding journal per line a rule fits (unless dryRun) and marks each line matched with the rule id; advances each rule's times_applied. Lines no rule fits are untouched.
Interpret the response
Read $.applied[].lineId for the returned bank_line identifier. Empty collections and nullable fields do not discover a target.
Call app_topolo_books.bank.lines.list with matchStatus matched and confirm the returned lineIds carry coded_by_rule_id; app_topolo_books.bank.rules.list shows times_applied advanced.
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.rules.apply --data @payload.json --json
topolo actions plan app_topolo_books.bank.rules.apply --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.bank.rules.apply --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.rules.apply",
"input": {
"dryRun": true
},
"resourceType": "workspace",
"resourceId": "<exact granted workspace id>",
"confirm": true,
"detail": true
}
}
Successful response · HTTP 200
Input · payload.json:
{
"dryRun": true
}
Captured response · HTTP 200
{
"dryRun": true,
"considered": 0,
"applied": [],
"skipped": [],
"unmatched": 0
}
HTTP 200. Call app_topolo_books.bank.lines.list with matchStatus matched and confirm the returned lineIds carry coded_by_rule_id; app_topolo_books.bank.rules.list shows times_applied advanced.
Refused response · auth_error
Input · payload.json:
{
"dryRun": true
}
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.
Verify the result
- Call app_topolo_books.bank.lines.list with matchStatus matched and confirm the returned lineIds carry coded_by_rule_id; app_topolo_books.bank.rules.list shows times_applied advanced.
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
Unmatch each lineId in applied; the coding journal is reversed and the line returns to unmatched.
Related actions
- 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.
- 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.
- Unmatch a bank line: Put a line back to unmatched: a coding or transfer journal is reversed (both lines of a transfer return), an exclusion is lifted. A line matched to a document payment is refused, since the payment is the record.
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.