Mercury: Retrieve ledger balances over a date range
Mercury books.getBooksLedgerBalances: arguments, response, policy and SDK examples.
← Books operations · Get started
Operation mercury.getbooksledgerbalances
Provider route: GET /books/ledger-balances. 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"]["getBooksLedgerBalances"]>[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.getBooksLedgerBalances(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.get_books_ledger_balances(arguments) result = await call.wait() return result.body_json()| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Additional keys: not allowed |
query | object | Required within parent | Additional keys: not allowed |
query.ledgerIds | array | Required within parent | |
query.ledgerIds[] | string | Each item | unique id for a ledger; emitted as base-58, but a base-16 UUID is also accepted Format: base58 (max length 22) |
query.startDate | string | Required within parent | Format: date |
query.endDate | string | Required within parent | Format: date |
query.booksId | string | Optional | The Books instance to act on. Must be the token organization’s own instance, which it defaults to. Format: uuid |
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 Retrieve ledger balances over a date range — response body |
Referenced models: Retrieve ledger balances over a date range — response body
Schemas
Section titled “Schemas”Retrieve ledger balances over a date range — response body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Response containing the balances of the requested ledgers. |
ledgerBalances | array | Required within parent | One entry per distinct requested ledger, in the order the ledgers were requested. |
ledgerBalances[] | Model | Each item | Expand Retrieve ledger balances over a date range — response body — ledger Balances item |
Referenced models: Retrieve ledger balances over a date range — response body — ledger Balances item
Retrieve ledger balances over a date range — response body — ledger Balances item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | One ledger's balances over the requested date range. Amounts are signed by the ledger's natural side: a positive amount is an increase on the side named by `debitCredit` (a debit ledger such as an asset grows with debits, a credit ledger such as a liability grows with credits), and a negative amount is a decrease. Balances are not flipped to a common debit-positive convention. Balances cover only the ledger's own line entries; they do not roll up the balances of its child ledgers. To get a parent's total, request its children as well and sum them, using `parentId` from the list ledgers endpoint. Opening-balance entries count. The Retained Earnings and Current Year Earnings system ledgers also include the calculated earnings, so their balances match the balance sheet. A ledger with no activity reports zeros. |
closingBalance | JSON | Required within parent | |
closingBalance (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
closingBalance (allOf 2) | JSON | All variants apply | The balance at the end of `endDate`. |
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 ledger has a natural debit or credit balance, which is the side that positive amounts increase. |
ledgerId | string | Required within parent | The ledger these balances belong to. Format: base58 (max length 22) |
name | string | Required within parent | The ledger's display name. |
netActivity | JSON | Required within parent | |
netActivity (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
netActivity (allOf 2) | JSON | All variants apply | The net change over the range: all of the ledger's line entries from `startDate` through `endDate`. |
openingBalance | JSON | Required within parent | |
openingBalance (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
openingBalance (allOf 2) | JSON | All variants apply | The balance at the end of the day before `startDate`. |
specialType | JSON | Optional | |
specialType (anyOf 1) | JSON | Alternative | |
specialType (anyOf 1) (allOf 1) | Model | All variants apply | Expand Retrieve ledger balances over a date range — response body — ledger Balances item special Type string string |
specialType (anyOf 1) (allOf 2) | JSON | All variants apply | The system function of a required ledger, such as `retained_earnings`, if it has one. |
specialType (anyOf 2) | null | Alternative | |
subType | JSON | Required within parent | |
subType (allOf 1) | string | All variants apply | Known values: currentAssets, nonCurrentAssets, transfersBetweenAccounts, uncategorizedAssets, currentLiabilities, nonCurrentLiabilities, equity, operatingRevenues, otherIncome, costOfGoodsSold, operatingExpenses, otherExpenses, retainedEarnings |
subType (allOf 2) | JSON | All variants apply | The ledger's more specific accounting classification. |
type | JSON | Required within parent | |
type (allOf 1) | string | All variants apply | Known values: asset, liability, equity, revenue, expense |
type (allOf 2) | JSON | All variants apply | The ledger's top-level accounting classification. |
Referenced models: Create a product — response body — unit Price value, Retrieve ledger balances over a date range — response body — ledger Balances item special Type string string
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]+)?$ |
Retrieve ledger balances over a date range — response body — ledger Balances item special Type string string
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | string | Root | Known values: uncatInflow, uncatOutflow, accountTransfers, openingBalances, accountsReceivable, accountsPayable, wagesExpense, bonusExpense, commissionsExpense, contractorExpense, employeeReimbursements, severanceExpense, payrollTaxExpense, employerBenefitsExpense, healthInsuranceExpense, wagesPayable, payrollTaxPayable, employeeBenefitLiabilities, payrollLiabilities, payrollAdjustmentsClearing, retainedEarnings, currentYearEarnings, benefitsExpense, donationsExpense, benefitsPayable, payrollTaxAccruals, stockExerciseClearing, payrollClearing |
Policy, approvals and errors
Section titled “Policy, approvals and errors”SDK function policy ID: mercury.getbooksledgerbalances. Catalog operation: mercury:getBooksLedgerBalances. 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.