Mercury: List the live chart of accounts
Mercury books.getBooksLedgers: arguments, response, policy and SDK examples.
← Books operations · Get started
Operation mercury.getbooksledgers
Provider route: GET /books/ledgers. 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"]["getBooksLedgers"]>[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.getBooksLedgers(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_ledgers(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 |
query.type | string | Optional | Only return ledgers of this type. One of: asset, liability, equity, revenue, expense |
query.subType | string | Optional | Only return ledgers of this sub-type. One of: currentAssets, nonCurrentAssets, transfersBetweenAccounts, uncategorizedAssets, currentLiabilities, nonCurrentLiabilities, equity, operatingRevenues, otherIncome, costOfGoodsSold, operatingExpenses, otherExpenses, retainedEarnings |
query.debitCredit | string | Optional | Only return ledgers with this natural balance. One of: debit, credit |
query.ids | array | Optional | Comma-separated list of at most 100 distinct ledger IDs. Only return these ledgers. Every ID must belong to the Books instance. Results are still paginated, so pass a `limit` of at least the number of IDs to get them all in one page. |
query.ids[] | 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.pageToken | string | Optional | token for pagination |
query.limit | integer | Optional | The maximum number of accounts to return per page, from 1 to 1000. Defaults to 50. Default: 50 Maximum: 1000 Minimum: 1 |
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 List the live chart of accounts — response body |
Referenced models: List the live chart of accounts — response body
Schemas
Section titled “Schemas”List the live chart of accounts — response body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Response containing a paginated list of ledgers in the organization's live chart of accounts. |
ledgers | array | Required within parent | The ledgers on this page. Use each ledger's @parentId@ to reconstruct hierarchy. |
ledgers[] | Model | Each item | Expand List the live chart of accounts — response body — ledgers item |
nextPageToken | JSON | Optional | |
nextPageToken (anyOf 1) | string | Alternative | Token to fetch the next page of results |
nextPageToken (anyOf 2) | null | Alternative | |
prevPageToken | JSON | Optional | |
prevPageToken (anyOf 1) | string | Alternative | Token to fetch the previous page of results |
prevPageToken (anyOf 2) | null | Alternative |
Referenced models: List the live chart of accounts — response body — ledgers item
List the live chart of accounts — response body — ledgers item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A general ledger in an organization's live chart of accounts. |
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. |
deletable | boolean | Required within parent | Whether the ledger can be deleted now. A ledger can't be deleted if it is required, has line entries, is linked to a bank or card account, or has an integration (invoicing, commerce, or a linked Plaid account) mapped to it. `deleteBlockedReason` says which. |
deleteBlockedReason | JSON | Optional | |
deleteBlockedReason (anyOf 1) | JSON | Alternative | |
deleteBlockedReason (anyOf 1) (allOf 1) | string | All variants apply | Known values: required, hasActivity, linkedSource, integrationMapped |
deleteBlockedReason (anyOf 1) (allOf 2) | JSON | All variants apply | Why the ledger can't be deleted. Absent when `deletable` is true. When several reasons apply, only one is given: `required` first, then `linkedSource` for a ledger fed by a Mercury account, since neither can be fixed. Fixing any other reason may reveal another. |
deleteBlockedReason (anyOf 2) | null | Alternative | |
editable | boolean | Required within parent | Whether line entries can be manually added to or removed from the ledger, for example by categorizing a transaction to it. False for ledgers whose activity a system controls, such as Mercury bank and card account ledgers and the accounts receivable and accounts payable required ledgers. |
financialAccountType | JSON | Optional | |
financialAccountType (anyOf 1) | JSON | Alternative | |
financialAccountType (anyOf 1) (allOf 1) | string | All variants apply | Known values: bankAccount, creditCard, payments, payroll, loan, prepaidCard, accountsReceivable, accountsPayable, investment, treasury |
financialAccountType (anyOf 1) (allOf 2) | JSON | All variants apply | The real-world financial account represented by this ledger, if any. |
financialAccountType (anyOf 2) | null | Alternative | |
id | string | Required within parent | The stable identifier for the ledger. Format: base58 (max length 22) |
isRequired | boolean | Required within parent | Whether the ledger is a required ledger, which the accounting system needs to operate. Required ledgers can't be deleted, and only their `name`, `sortCode`, and `parentId` can be changed. |
name | string | Required within parent | The ledger's display name. Format: size < 256 |
openingBalance | JSON | Optional | |
openingBalance (anyOf 1) | JSON | Alternative | |
openingBalance (anyOf 1) (allOf 1) | Model | All variants apply | Expand Create a product — response body — unit Price value |
openingBalance (anyOf 1) (allOf 2) | JSON | All variants apply | The ledger's opening balance in its natural direction (`debitCredit`): positive is a balance on the ledger's natural side, negative on the opposite side. Absent when the ledger has no opening balance. Returned by getBooksLedgers and getBooksLedger only; absent from the ledgers in create and update results. Set or clear it with setBooksLedgerOpeningBalances. |
openingBalance (anyOf 2) | null | Alternative | |
parentId | JSON | Optional | |
parentId (anyOf 1) | string | Alternative | The identifier of the ledger's parent, if it is nested. Format: base58 (max length 22) |
parentId (anyOf 2) | null | Alternative | |
requiredLedgerPurpose | JSON | Optional | |
requiredLedgerPurpose (anyOf 1) | JSON | Alternative | |
requiredLedgerPurpose (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 |
requiredLedgerPurpose (anyOf 1) (allOf 2) | JSON | All variants apply | The system function a required ledger fulfills, such as holding uncategorized inflows. Absent for ledgers that aren't required. |
requiredLedgerPurpose (anyOf 2) | null | Alternative | |
sortCode | string | Required within parent | The ledger/account number used for chart ordering and template mapping. Format: size < 21 |
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. It must belong to the ledger's `type`: `asset`: `currentAssets`, `nonCurrentAssets`, `transfersBetweenAccounts`, `uncategorizedAssets`; `liability`: `currentLiabilities`, `nonCurrentLiabilities`; `equity`: `equity`, `retainedEarnings`; `revenue`: `operatingRevenues`, `otherIncome`; `expense`: `costOfGoodsSold`, `operatingExpenses`, `otherExpenses`. A child ledger has the same type and sub-type as its parent. |
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. A sub-ledger has the same type as the root of its hierarchy. |
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.getbooksledgers. Catalog operation: mercury:getBooksLedgers. 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.