Topolo Docs Topolo Platform
Open workspace

Create a bank rule

Add a rule: when an unmatched statement line matches matchText in matchField (case-insensitive), moves in the given direction and within the amount range, code it to accountId with the optional contact, tax rate and memo. Lower priority numbers run first. The account must be active; the rule is refused with coding_to_bank_account when applied to lines of the bank account it names.

Outcome

Add a rule: when an unmatched statement line matches matchText in matchField (case-insensitive), moves in the given direction and within the amount range, code it to accountId with the optional contact, tax rate and memo. Lower priority numbers run first. The account must be active; the rule is refused with coding_to_bank_account when applied to lines of the bank account it names.

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.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.
  • bankAccountId: Exact local bank account.id from bank.accounts.list; a provider account identifier is separate.
  • accountId: Exact account.id from accounts.list/get; a chart code is not an id.
  • contactId: Exact contact.id from contacts.list/get; a name or email address is not an id.
  • taxRateId: Resolve this exact identifier through the related published reads for the same organization and workspace; never infer it from a name.

Request

POST /api/bank/rules

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

Input fields

FieldRequiredMeaningSchema and constraints
nameRequiredname{"type":"string","minLength":1,"maxLength":120}
bankAccountIdOptionalExact local bank account.id from bank.accounts.list; a provider account identifier is separate.{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]}
directionOptionaldirection{"type":"string","enum":["in","out","any"]}
matchFieldOptionalmatch Field{"type":"string","enum":["description","counterparty","either"]}
matchKindOptionalmatch Kind{"type":"string","enum":["contains","equals","starts_with"]}
matchTextRequiredmatch Text{"type":"string","minLength":1,"maxLength":200}
amountMinMinorOptionalamount Min Minor{"anyOf":[{"type":"integer","minimum":0,"maximum":9007199254740991},{"type":"null"}]}
amountMaxMinorOptionalamount Max Minor{"anyOf":[{"type":"integer","minimum":0,"maximum":9007199254740991},{"type":"null"}]}
accountIdRequiredExact account.id from accounts.list/get; a chart code is not an id.{"type":"string","minLength":1}
contactIdOptionalExact contact.id from contacts.list/get; a name or email address is not an id.{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]}
taxRateIdOptionaltax Rate Id{"anyOf":[{"type":"string","minLength":1},{"type":"null"}]}
memoOptionalmemo{"anyOf":[{"type":"string","maxLength":500},{"type":"null"}]}
priorityOptionalpriority{"type":"integer","minimum":1,"maximum":9999}

Inspect nested fields and the complete input schema.

Effects

  • Inserts one active rule. Nothing is coded until bank.rules.apply runs (or a person applies it from Reconcile).

Interpret the response

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

Call app_topolo_books.bank.rules.list and confirm the rule is present with the fields you sent.

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.create --data @payload.json --json
topolo actions plan app_topolo_books.bank.rules.create --resource-type workspace --resource-id "$BOOKS_WORKSPACE_ID" --data @payload.json --json
topolo actions call app_topolo_books.bank.rules.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.bank.rules.create",
    "input": {
      "name": "Fees",
      "matchText": "fee",
      "direction": "out",
      "accountId": "acc_6d2ff297f77342e0a956958fd027ea0b"
    },
    "resourceType": "workspace",
    "resourceId": "<exact granted workspace id>",
    "confirm": true,
    "detail": true
  }
}

Successful response · HTTP 201

Input · payload.json:

{
  "name": "Fees",
  "matchText": "fee",
  "direction": "out",
  "accountId": "acc_6d2ff297f77342e0a956958fd027ea0b"
}

Captured response · HTTP 201

{
  "rule": {
    "id": "brl_51c61882d14a493fba93c2a0c704d045",
    "organization_id": "org_brl_muvnpysr4",
    "workspace_id": "ws_brl_muvnpysr4",
    "name": "Fees",
    "bank_account_id": null,
    "direction": "out",
    "match_field": "description",
    "match_kind": "contains",
    "match_text": "fee",
    "amount_min_minor": null,
    "amount_max_minor": null,
    "account_id": "acc_6d2ff297f77342e0a956958fd027ea0b",
    "contact_id": null,
    "tax_rate_id": null,
    "memo": null,
    "priority": 100,
    "status": "active",
    "times_applied": 0,
    "last_applied_at": null,
    "created_by": "usr_test",
    "created_at": "2026-10-05T19:42:54.325Z",
    "updated_at": "2026-10-05T19:42:54.325Z"
  }
}

HTTP 201. Call app_topolo_books.bank.rules.list and confirm the rule is present with the fields you sent.

Refused response · auth_error

Input · payload.json:

{
  "name": "Stripe payouts",
  "matchField": "description",
  "matchKind": "starts_with",
  "matchText": "STRIPE PAYOUT",
  "direction": "in",
  "accountId": "acc_4000",
  "priority": 10
}

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.rules.list and confirm the rule is present with the fields you sent.

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

Archive the returned rule id.

  • Apply bank rules: 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.
  • List bank rules: The rules that code statement lines automatically, lowest priority number first; archived ones only with includeArchived true. Each says what it looks at (description, counterparty or either), how it matches (contains, equals, starts_with), the direction and amount range it applies to, the bank account it is limited to, where it codes (account, contact, tax rate, memo) and how many times it has run.
  • 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.
  • Archive a bank rule: Stop the rule running. Lines it coded keep its id as their provenance.

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.