Skip to content

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.

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 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_ledger_balances(arguments)
result = await call.wait()
return result.body_json()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
queryobjectRequired within parentAdditional keys: not allowed
query.ledgerIdsarrayRequired within parent
query.ledgerIds[]stringEach itemunique id for a ledger; emitted as base-58, but a base-16 UUID is also accepted
Format: base58 (max length 22)
query.startDatestringRequired within parentFormat: date
query.endDatestringRequired within parentFormat: date
query.booksIdstringOptionalThe Books instance to act on. Must be the token organization’s own instance, which it defaults to.
Format: uuid

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

FieldTypePresenceDescription and constraints
$ModelRootExpand Retrieve ledger balances over a date range — response body

Referenced models: Retrieve ledger balances over a date range — response body

Retrieve ledger balances over a date range — response body
FieldTypePresenceDescription and constraints
$objectRootResponse containing the balances of the requested ledgers.
ledgerBalancesarrayRequired within parentOne entry per distinct requested ledger, in the order the ledgers were requested.
ledgerBalances[]ModelEach itemExpand 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
FieldTypePresenceDescription and constraints
$objectRootOne 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.
closingBalanceJSONRequired within parent
closingBalance (allOf 1)ModelAll variants applyExpand Create a product — response body — unit Price value
closingBalance (allOf 2)JSONAll variants applyThe balance at the end of `endDate`.
debitCreditJSONRequired within parent
debitCredit (allOf 1)stringAll variants applyKnown values: debit, credit
debitCredit (allOf 2)JSONAll variants applyWhether the ledger has a natural debit or credit balance, which is the side that positive amounts increase.
ledgerIdstringRequired within parentThe ledger these balances belong to.
Format: base58 (max length 22)
namestringRequired within parentThe ledger's display name.
netActivityJSONRequired within parent
netActivity (allOf 1)ModelAll variants applyExpand Create a product — response body — unit Price value
netActivity (allOf 2)JSONAll variants applyThe net change over the range: all of the ledger's line entries from `startDate` through `endDate`.
openingBalanceJSONRequired within parent
openingBalance (allOf 1)ModelAll variants applyExpand Create a product — response body — unit Price value
openingBalance (allOf 2)JSONAll variants applyThe balance at the end of the day before `startDate`.
specialTypeJSONOptional
specialType (anyOf 1)JSONAlternative
specialType (anyOf 1) (allOf 1)ModelAll variants applyExpand Retrieve ledger balances over a date range — response body — ledger Balances item special Type string string
specialType (anyOf 1) (allOf 2)JSONAll variants applyThe system function of a required ledger, such as `retained_earnings`, if it has one.
specialType (anyOf 2)nullAlternative
subTypeJSONRequired within parent
subType (allOf 1)stringAll variants applyKnown values: currentAssets, nonCurrentAssets, transfersBetweenAccounts, uncategorizedAssets, currentLiabilities, nonCurrentLiabilities, equity, operatingRevenues, otherIncome, costOfGoodsSold, operatingExpenses, otherExpenses, retainedEarnings
subType (allOf 2)JSONAll variants applyThe ledger's more specific accounting classification.
typeJSONRequired within parent
type (allOf 1)stringAll variants applyKnown values: asset, liability, equity, revenue, expense
type (allOf 2)JSONAll variants applyThe 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
FieldTypePresenceDescription and constraints
$JSONRoot
$ (anyOf 1)numberAlternativeA dollar amount
Format: double
$ (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
Retrieve ledger balances over a date range — response body — ledger Balances item special Type string string
FieldTypePresenceDescription and constraints
$stringRootKnown 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

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.

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.