Mercury: Create ledgers (general ledger accounts)
Mercury books.createBooksLedgers: arguments, response, policy and SDK examples.
← Books operations · Get started
Operation mercury.createbooksledgers
Provider route: POST /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"]["createBooksLedgers"]>[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.createBooksLedgers(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.create_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 |
body | Model | Optional | Expand Create ledgers (general ledger accounts) — request body — body |
Referenced models: Create ledgers (general ledger accounts) — 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 Create ledgers (general ledger accounts) — response body |
Referenced models: Create ledgers (general ledger accounts) — response body
Schemas
Section titled “Schemas”1 more schema is linked from the tables above, on the schema pages.
Create ledgers (general ledger accounts) — response body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | One result per requested ledger, in request order. |
failedCount | JSON | Required within parent | |
failedCount (anyOf 1) | integer | Alternative | How many items in `results` failed, each with an `error`. Zero exactly when every item succeeded. `succeededCount` plus `failedCount` always equals the number of `results`. Maximum: 9223372036854776000 Minimum: -9223372036854776000 |
failedCount (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
results | array | Required within parent | One result per requested ledger, in request order. A failed item does not fail the others. |
results[] | Model | Each item | Expand Create ledgers (general ledger accounts) — response body — results item |
succeededCount | JSON | Required within parent | |
succeededCount (anyOf 1) | integer | Alternative | How many items in `results` succeeded. Maximum: 9223372036854776000 Minimum: -9223372036854776000 |
succeededCount (anyOf 2) | string | Alternative | Pattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$ |
Referenced models: Create ledgers (general ledger accounts) — response body — results item
Create ledgers (general ledger accounts) — request body — body
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Request to create general ledgers. Additional keys: not allowed |
ledgers | array | Required within parent | The ledgers to create, from 1 to 100 ('maxBooksAPILedgerWrites'). Minimum items: 1 |
ledgers[] | Model | Each item | Expand Create ledgers (general ledger accounts) — request body — body ledgers item |
Referenced models: Create ledgers (general ledger accounts) — request body — body ledgers item
Create ledgers (general ledger accounts) — response body — results item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | The outcome of creating one requested ledger: exactly one of `ledger` and `error` is set. |
error | JSON | Optional | |
error (anyOf 1) | JSON | Alternative | |
error (anyOf 1) (allOf 1) | Model | All variants apply | Expand Set or clear ledger opening balances — response body — results item error code, message code, message |
error (anyOf 1) (allOf 2) | JSON | All variants apply | Why the ledger was not created, when it wasn't. |
error (anyOf 2) | null | Alternative | |
ledger | JSON | Optional | |
ledger (anyOf 1) | JSON | Alternative | |
ledger (anyOf 1) (allOf 1) | Model | All variants apply | Expand List the live chart of accounts — response body — ledgers item |
ledger (anyOf 1) (allOf 2) | JSON | All variants apply | The created ledger, when it was created. |
ledger (anyOf 2) | null | Alternative |
Referenced models: List the live chart of accounts — response body — ledgers item, Set or clear ledger opening balances — response body — results item error code, message code, message
Create ledgers (general ledger accounts) — request body — body ledgers item
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | A general ledger to create. Additional keys: not allowed |
debitCredit | JSON | Required within parent | |
debitCredit (allOf 1) | string | All variants apply | One of: debit, credit |
debitCredit (allOf 2) | JSON | All variants apply | Whether the ledger has a debit or credit nature |
name | string | Required within parent | The ledger name Format: size < 256 |
parentId | JSON | Optional | |
parentId (anyOf 1) | string | Alternative | Optional parent ledger, to create this ledger as a child ledger Format: base58 (max length 22) |
parentId (anyOf 2) | null | Alternative | |
sortCode | string | Required within parent | Numeric sort code used to order the ledger in the chart of accounts Format: matches ^[0-9]+$, size < 21 |
subType | JSON | Required within parent | |
subType (allOf 1) | string | All variants apply | One of: currentAssets, nonCurrentAssets, transfersBetweenAccounts, uncategorizedAssets, currentLiabilities, nonCurrentLiabilities, equity, operatingRevenues, otherIncome, costOfGoodsSold, operatingExpenses, otherExpenses, retainedEarnings |
subType (allOf 2) | JSON | All variants apply | The ledger sub-type |
type | JSON | Required within parent | |
type (allOf 1) | string | All variants apply | One of: asset, liability, equity, revenue, expense |
type (allOf 2) | JSON | All variants apply | The ledger type |
Set or clear ledger opening balances — response body — results item error code, message code, message
| Field | Type | Presence | Description and constraints |
|---|---|---|---|
$ | object | Root | Why one ledger in a bulk create, update, or delete failed. A failed item never fails the whole request; the other items still succeed or fail on their own. |
code | JSON | Required within parent | |
code (allOf 1) | string | All variants apply | Known values: invalidLedger, missingParameters, duplicateName, duplicateSortCode, invalidLedgerType, invalidLedgerParent, invalidLedgerReportCashFlow, deletingRequiredLedger, deletingLedgerWithActivity, deletingLinkedLedger, deletingParentLedger, modifyingRequiredLedger, integrationMapped, invalidUnappliedPaymentsLedger, deletingMappedLedger, modifyingMappedLedger, mercuryAccountLedger, unknownError |
code (allOf 2) | JSON | All variants apply | Stable code for the failure. |
message | string | Required within parent | What went wrong and how to fix it, suitable to show to a user. |
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.createbooksledgers. Catalog operation: mercury:createBooksLedgers. 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.