Skip to content

Mercury: List categorization rules

Mercury books.getBooksCategorizationRules: arguments, response, policy and SDK examples.

← Books operations · Get started

Operation mercury.getbookscategorizationrules

Provider route: GET /books/rules. Alter supplies the connection’s credentials and routing.

Install @alter-ai/sdk @alter-ai/mercury with npm, or alter-sdk-mercury with pip. Supply your connected customer’s grant ID and the arguments described below.

import { App } from "@alter-ai/sdk";
import { MercuryIntegration } from "@alter-ai/mercury";
async function execute(input: Parameters<MercuryIntegration["books"]["getBooksCategorizationRules"]>[0]) {
const app = new App({ apiKey: process.env.ALTER_API_KEY! });
try {
const provider = new MercuryIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! });
const call = await provider.books.getBooksCategorizationRules(input);
const result = await call.wait();
return result.bodyJson();
} finally {
await app.close();
}
}
import os
from alter_sdk import App
from alter_sdk_mercury import MercuryIntegration
async def execute(arguments):
async with App(api_key=os.environ["ALTER_API_KEY"]) as app:
provider = MercuryIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]})
call = await provider.books.get_books_categorization_rules(arguments)
result = await call.wait()
return result.body_json()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
queryobjectOptionalAdditional keys: not allowed
query.booksIdstringOptionalThe Books instance to act on. Must be the token organization’s own instance, which it defaults to.
Format: uuid
query.pageTokenstringOptionaltoken for pagination
query.limitintegerOptionalThe maximum number of rules to return per page, from 1 to 100. Defaults to 50.
Default: 50
Maximum: 100
Minimum: 1

Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.

FieldTypePresenceDescription and constraints
$ModelRootExpand List categorization rules — response body

Referenced models: List categorization rules — response body

6 more schemas are linked from the tables above, on the schema pages.

List categorization rules — response body
FieldTypePresenceDescription and constraints
$objectRootA page of a Books instance's categorization rules, in priority order.
nextPageTokenJSONOptional
nextPageToken (anyOf 1)stringAlternativePass as `pageToken` to fetch the next page, or null on the last page.
nextPageToken (anyOf 2)nullAlternative
rulesarrayRequired within parentThe rules on this page, highest priority first. When several rules match a transaction, the first one applies. Rules Books can't represent are omitted.
rules[]ModelEach itemExpand List categorization rules — response body — rules item

Referenced models: List categorization rules — response body — rules item

List categorization rules — response body — rules item
FieldTypePresenceDescription and constraints
$objectRootA categorization rule: when a transaction matches all its `conditions`, Books applies its `outputs`, such as categorizing the transaction to a ledger. Only rules that Books can represent are listed: a rule with a condition or output outside this vocabulary (for example, an accounting-integration rule that sets a Mercury custom category), or whose GL account no longer maps to a Books ledger, is omitted.
conditionsarrayRequired within parentThe conditions a transaction must match. At least one; every condition must match (logical AND). There is no OR: an "any of" rule is written as separate rules.
Minimum items: 1
conditions[]ModelEach itemExpand List categorization rules — response body — rules item conditions item
glCodeNameJSONOptional
glCodeName (anyOf 1)stringAlternativeThe display name of the general ledger (GL) account the rule categorizes to. Absent when the rule sets none.
glCodeName (anyOf 2)nullAlternative
idstringRequired within parentThe rule's stable identifier.
Format: uuid
lastAppliedJSONOptional
lastApplied (anyOf 1)JSONAlternative
lastApplied (anyOf 1) (allOf 1)stringAll variants applyFormat: yyyy-mm-ddThh:MM:ssZ
lastApplied (anyOf 1) (allOf 2)JSONAll variants applyThe last time the rule matched a transaction. Absent if it never has.
lastApplied (anyOf 2)nullAlternative
outputsarrayRequired within parentWhat the rule applies to a matching transaction. At least one.
Minimum items: 1
outputs[]ModelEach itemExpand List categorization rules — response body — rules item outputs item
statusJSONRequired within parent
status (allOf 1)stringAll variants applyKnown values: active, inactive, invalid
status (allOf 2)JSONAll variants applyWhether the rule currently categorizes transactions.

Referenced models: List categorization rules — response body — rules item conditions item, List categorization rules — response body — rules item outputs item

List categorization rules — response body — rules item conditions item
FieldTypePresenceDescription and constraints
$JSONRootA condition a transaction must match for a categorization rule to apply. `tag` says which condition it is (`amount`, `description`, `counterparty`, `debitCard`, `creditCard`, `user`, or `customCategory`) and `contents` holds its fields. A rule's conditions must all match; there is no OR, so an "any of" rule is written as separate rules.
$ (anyOf 1)objectAlternative
$ (anyOf 1).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: amount contents
$ (anyOf 1).tagstringRequired within parentKnown values: amount
$ (anyOf 2)objectAlternative
$ (anyOf 2).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: description contents
$ (anyOf 2).tagstringRequired within parentKnown values: description
$ (anyOf 3)objectAlternative
$ (anyOf 3).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: counterparty contents
$ (anyOf 3).tagstringRequired within parentKnown values: counterparty
$ (anyOf 4)objectAlternative
$ (anyOf 4).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: debit Card contents
$ (anyOf 4).tagstringRequired within parentKnown values: debitCard
$ (anyOf 5)objectAlternative
$ (anyOf 5).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: credit Card contents
$ (anyOf 5).tagstringRequired within parentKnown values: creditCard
$ (anyOf 6)objectAlternative
$ (anyOf 6).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: user contents
$ (anyOf 6).tagstringRequired within parentKnown values: user
$ (anyOf 7)objectAlternative
$ (anyOf 7).contentsModelRequired within parentExpand List categorization rules — response body — rules / item / conditions / item / tag: custom Category contents
$ (anyOf 7).tagstringRequired within parentKnown values: customCategory

Referenced models: List categorization rules — response body — rules / item / conditions / item / tag: amount contents, List categorization rules — response body — rules / item / conditions / item / tag: counterparty contents, List categorization rules — response body — rules / item / conditions / item / tag: credit Card contents, List categorization rules — response body — rules / item / conditions / item / tag: custom Category contents, List categorization rules — response body — rules / item / conditions / item / tag: debit Card contents, List categorization rules — response body — rules / item / conditions / item / tag: description contents, List categorization rules — response body — rules / item / conditions / item / tag: user contents

List categorization rules — response body — rules item outputs item
FieldTypePresenceDescription and constraints
$objectRootWhat a categorization rule does to a transaction it matches. `tag` says which output it is and `contents` holds its fields; today the only output is `setLedger`, which categorizes the transaction to the ledger `contents.ledgerId`.
contentsModelRequired within parentExpand List categorization rules — response body — rules item outputs item contents
tagstringRequired within parentKnown values: setLedger

Referenced models: List categorization rules — response body — rules item outputs item contents

List categorization rules — response body — rules / item / conditions / item / tag: amount contents
FieldTypePresenceDescription and constraints
$objectRootMatches transactions whose amount compares to a threshold (`tag`: `amount`). The amount is signed: money in (credits) is positive and money out (debits) is negative, and the threshold is compared against it as is, so `lessThan` `-50` matches outflows of more than $50. A range is two amount conditions on the same rule.
amountJSONRequired within parent
amount (allOf 1)ModelAll variants applyExpand Create a product — response body — unit Price value
amount (allOf 2)JSONAll variants applyThe threshold, in dollars. Signed like the transaction amount: positive for money in, negative for money out.
operatorJSONRequired within parent
operator (allOf 1)stringAll variants applyKnown values: lessThan, lessThanOrEqualTo, greaterThan, greaterThanOrEqualTo, equalTo
operator (allOf 2)JSONAll variants applyHow to compare the transaction amount to `amount`.

Referenced models: Create a product — response body — unit Price value

List categorization rules — response body — rules / item / conditions / item / tag: counterparty contents
FieldTypePresenceDescription and constraints
$objectRootMatches transactions whose counterparty name is exactly a name (`tag`: `counterparty`). Only Mercury transactions carry a counterparty.
namestringRequired within parentThe counterparty name the transaction must have, matched exactly.
List categorization rules — response body — rules / item / conditions / item / tag: credit Card contents
FieldTypePresenceDescription and constraints
$objectRootMatches transactions made with a Mercury credit card (`tag`: `creditCard`).
creditCardIdJSONRequired within parent
creditCardId (allOf 1)stringAll variants applyFormat: uuid
creditCardId (allOf 2)JSONAll variants applyThe ID of the credit card.

SDK function policy ID: mercury.getbookscategorizationrules. Catalog operation: mercury:getBooksCategorizationRules. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.

Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.

Official provider source

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand how our website, product, and documentation are used.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

Advertising

Shares visits and sign-ups with Meta, Reddit, and X so we can measure which of our ads work.

You can change these choices at any time from Cookie settings.