Mercury: Categorize or split transactions
Mercury books.categorizeBooksTransactions: arguments, response, policy and SDK examples.
← Books operations · Get started
Operation mercury.categorizebookstransactions
Provider route: POST /books/transactions/categorize. Alter supplies the connection’s credentials and routing.
Call through Alter
Section titled “Call through Alter”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"]["categorizeBooksTransactions"]>[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.categorizeBooksTransactions(input); const result = await call.wait(); return result.bodyJson(); } finally { await app.close(); }}import osfrom alter_sdk import Appfrom 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.categorize_books_transactions(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
query | object | Optional | Additional keys: not allowed |
query.booksId | string | Optional | The Books instance to act on. Must be the token organization’s own instance, which it defaults to. Format: uuid |
body | Model | Optional | Expand Categorize or split transactions — request body — body |
Referenced models: Categorize or split transactions — request body — body
Response
Section titled “Response”Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | Model | Root | Expand Categorize or split transactions — response body |
Referenced models: Categorize or split transactions — response body
Schemas
Section titled “Schemas”Categorize or split transactions — response body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | The categorized transactions, in request order. |
items | array | Required within parent | One per request item, in request order. |
items[] | Model | Each item | Expand Categorize or split transactions — response body — items item |
Referenced models: Categorize or split transactions — response body — items item
Categorize or split transactions — request body — body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Request to categorize or split one or more transactions, all or nothing. Additional keys: not allowed |
items | array | Required within parent | The transactions to categorize, from 1 to 100, each at most once. Across all items, the splits may name at most 100 distinct ledgers. |
items[] | Model | Each item | Expand Categorize or split transactions — request body — body items item |
Referenced models: Categorize or split transactions — request body — body items item
Categorize or split transactions — response body — items item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A transaction's categorization after the request. |
categorizationLines | array | Required within parent | The transaction's categorization lines, as the transaction's `categorizationLines` now list them. |
categorizationLines[] | Model | Each item | Expand Categorize or split transactions — response body — items item categorization Lines item |
journalEntryId | string | Required within parent | The `journalEntryId` of the transaction. Format: base58 (max length 22) |
Referenced models: Categorize or split transactions — response body — items item categorization Lines item
Categorize or split transactions — request body — body items item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | The new categorization of one transaction. Additional keys: not allowed |
journalEntryId | string | Required within parent | The `journalEntryId` of the transaction to categorize. Format: base58 (max length 22) |
splits | array | Required within parent | The new categorization: one split per category. The splits replace every current categorization line. Minimum items: 1 |
splits[] | Model | Each item | Expand Categorize or split transactions — request body — body items item splits item |
Referenced models: Categorize or split transactions — request body — body items item splits item
Categorize or split transactions — response body — items item categorization Lines item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A line of a transaction's journal entry other than its own line on the source account's ledger. Its ledger is the transaction's category; a split transaction has one line per category. |
amount | JSON | Required within parent | |
amount (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
amount (allOf 2) | JSON | All variants apply | The unsigned amount of the line, in dollars; `debitCredit` gives its direction. |
debitCredit | JSON | Required within parent | |
debitCredit (allOf 1) | string | All variants apply | Known values: debit, credit |
debitCredit (allOf 2) | JSON | All variants apply | Whether the amount is a debit or a credit to the ledger. |
ledgerId | string | Required within parent | The identifier of the ledger (general ledger account) the line posts to, i.e. the category. Format: base58 (max length 22) |
ledgerName | string | Required within parent | The display name of the ledger the line posts to. |
lineEntryId | string | Required within parent | The identifier of the categorization line entry. Format: base58 (max length 22) |
Referenced models: Create a product — response body — unit Price value
Categorize or split transactions — request body — body items item splits item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | One category of a transaction and the part of its amount that goes to it. Additional keys: not allowed |
amount | JSON | Required within parent | |
amount (allOf 1) | number | All variants apply | A dollar amount Format: double |
amount (allOf 2) | JSON | All variants apply | The signed, nonzero part of the transaction's amount: a number of dollars with at most two decimal places, with the same sign convention as the transaction's `amount`. The splits of a transaction must add up to exactly its `amount`. A split with the opposite sign to the transaction, such as a refund netted against a purchase, posts on the other side. |
description | JSON | Optional | |
description (anyOf 1) | string | Alternative | The description of the categorization line. Omit to keep the description of the line it replaces, or for a new line, to use the transaction's description. Format: size < 4001 |
description (anyOf 2) | null | Alternative | |
ledgerId | string | Required within parent | The ledger (general ledger account) to categorize this part of the transaction to, such as an expense or revenue account. It must be editable, and must not be an uncategorized ledger or a source account's ledger. Format: base58 (max length 22) |
tagIds | JSON | Optional | |
tagIds (anyOf 1) | array | Alternative | The tags of the categorization line. Omit to keep the tags of the line it replaces; a new line then has no tags. |
tagIds (anyOf 1)[] | string | Each item | unique id for a tag; emitted as base-58, but a base-16 UUID is also accepted Format: base58 (max length 22) |
tagIds (anyOf 2) | null | Alternative |
Create a product — response body — unit Price value
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | JSON | Root | |
$ (anyOf 1) | number | Alternative | A dollar amount Format: double |
$ (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: mercury.categorizebookstransactions. Catalog operation: mercury:categorizeBooksTransactions. 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.