Skip to content

Mercury: Create a categorization rule

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

← Books operations · Get started

Operation mercury.createbookscategorizationrule

Provider route: POST /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"]["createBooksCategorizationRule"]>[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.createBooksCategorizationRule(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.create_books_categorization_rule(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. Required for agent organization tokens; defaults to the token organization’s instance.
Format: uuid
bodyModelOptionalExpand Create a categorization rule — request body — body

Referenced models: Create a categorization rule — request body — body

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

FieldTypePresenceDescription and constraints
$ModelRootExpand Create a categorization rule — response body

Referenced models: Create a categorization rule — response body

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

Create a categorization rule — response body
FieldTypePresenceDescription and constraints
$objectRootThe created categorization rule.
ruleJSONRequired within parent
rule (allOf 1)ModelAll variants applyExpand List categorization rules — response body — rules item
rule (allOf 2)JSONAll variants applyThe created rule, as the list endpoint returns it.

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

Create a categorization rule — request body — body
FieldTypePresenceDescription and constraints
$objectRootA categorization rule to create. There is no priority field: Books places the new rule among the existing ones by how specific its conditions are.
Additional keys: not allowed
conditionsarrayRequired within parentThe conditions a transaction must match, from 1 to 10. Every condition must match (logical AND); there is no OR, so an "any of" rule is written as separate rules. The organization may not already have a rule with the same conditions.
Minimum items: 1
conditions[]ModelEach itemExpand Create a categorization rule — request body — body conditions item
outputsarrayRequired within parentWhat the rule applies to a matching transaction: at most one output of each kind, so today exactly one `setLedger`. Its ledger must be one the caller may edit in this Books instance.
Minimum items: 1
outputs[]ModelEach itemExpand Create a categorization rule — request body — body outputs item

Referenced models: Create a categorization rule — request body — body conditions item, Create a categorization rule — request body — body outputs 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

Create a categorization rule — request body — body 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.
$ (oneOf 1)objectAlternativeAdditional keys: not allowed
$ (oneOf 1).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: amount contents
$ (oneOf 1).tagstringRequired within parentOne of: amount
$ (oneOf 2)objectAlternativeAdditional keys: not allowed
$ (oneOf 2).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: description contents
$ (oneOf 2).tagstringRequired within parentOne of: description
$ (oneOf 3)objectAlternativeAdditional keys: not allowed
$ (oneOf 3).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: counterparty contents
$ (oneOf 3).tagstringRequired within parentOne of: counterparty
$ (oneOf 4)objectAlternativeAdditional keys: not allowed
$ (oneOf 4).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: debit Card contents
$ (oneOf 4).tagstringRequired within parentOne of: debitCard
$ (oneOf 5)objectAlternativeAdditional keys: not allowed
$ (oneOf 5).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: credit Card contents
$ (oneOf 5).tagstringRequired within parentOne of: creditCard
$ (oneOf 6)objectAlternativeAdditional keys: not allowed
$ (oneOf 6).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: user contents
$ (oneOf 6).tagstringRequired within parentOne of: user
$ (oneOf 7)objectAlternativeAdditional keys: not allowed
$ (oneOf 7).contentsModelRequired within parentExpand Create a categorization rule — request body — body / conditions / item / tag: custom Category contents
$ (oneOf 7).tagstringRequired within parentOne of: customCategory

Referenced models: Create a categorization rule — request body — body / conditions / item / tag: amount contents, Create a categorization rule — request body — body / conditions / item / tag: counterparty contents, Create a categorization rule — request body — body / conditions / item / tag: credit Card contents, Create a categorization rule — request body — body / conditions / item / tag: custom Category contents, Create a categorization rule — request body — body / conditions / item / tag: debit Card contents, Create a categorization rule — request body — body / conditions / item / tag: description contents, Create a categorization rule — request body — body / conditions / item / tag: user contents

Create a categorization rule — request body — body 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`.
Additional keys: not allowed
contentsModelRequired within parentExpand Create a categorization rule — request body — body outputs item contents
tagstringRequired within parentOne of: setLedger

Referenced models: Create a categorization rule — request body — body outputs item 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

SDK function policy ID: mercury.createbookscategorizationrule. Catalog operation: mercury:createBooksCategorizationRule. 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.