Skip to content

Mercury: Retrieve a profit and loss statement

Mercury books.getBooksProfitAndLoss: arguments, response, policy and SDK examples.

← Books operations · Get started

Operation mercury.getbooksprofitandloss

Provider route: GET /books/reports/profit-and-loss. 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"]["getBooksProfitAndLoss"]>[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.getBooksProfitAndLoss(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_profit_and_loss(arguments)
result = await call.wait()
return result.body_json()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
queryobjectOptionalAdditional keys: not allowed
query.booksIdstringOptionalThe Books instance to act on. Must be the token organization’s own instance, which it defaults to.
Format: uuid
query.startDatestringOptionalThe report covers the period containing this day and every later period. Defaults to the Books entries start date, or the earliest date the span limit allows for the end date, whichever is later, but never after the end date.
Format: date
query.endDatestringOptionalThe report covers the period containing this day and every earlier period. Must be on or after startDate. Defaults to today (UTC), or the latest date the span limit allows for startDate, whichever is earlier, but never before startDate.
Format: date
query.periodstringOptionalThe length of time each column covers. Daily reports can span at most 1 year; other periods at most 5 years. Defaults to a single column covering the whole range, which can also span at most 5 years.
One of: daily, monthly, quarterly, yearly
query.includeEmptybooleanOptionalWhether to include ledgers with no activity. Defaults to false.
query.includeOnlyClosedbooleanOptionalWhether to include only activity dated before the latest close. Defaults to false.

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

FieldTypePresenceDescription and constraints
$ModelRootExpand Retrieve a balance sheet — response body

Referenced models: Retrieve a balance sheet — response body

Retrieve a balance sheet — response body
FieldTypePresenceDescription and constraints
$objectRootAn income statement or balance sheet broken down into columns.
columnsarrayRequired within parentThe report's columns, in chronological order.
columns[]ModelEach itemExpand Retrieve a balance sheet — response body — columns item
retainedEarningsJSONOptional
retainedEarnings (anyOf 1)JSONAlternative
retainedEarnings (anyOf 1) (allOf 1)ModelAll variants applyExpand Retrieve a balance sheet — response body — retained Earnings calculated Current Year Earnings, calculated Retained Earnings calculated Current Year Earnings, calculated Retained Earnings
retainedEarnings (anyOf 1) (allOf 2)JSONAll variants applySystem-calculated equity amounts. Present on balance sheets; omitted on income statements.
retainedEarnings (anyOf 2)nullAlternative
rowsarrayRequired within parentThe report's top-level rows.
rows[]ModelEach itemExpand Retrieve a balance sheet — response body — rows item

Referenced models: Retrieve a balance sheet — response body — columns item, Retrieve a balance sheet — response body — rows item, Retrieve a balance sheet — response body — retained Earnings calculated Current Year Earnings, calculated Retained Earnings calculated Current Year Earnings, calculated Retained Earnings

Retrieve a balance sheet — response body — columns item
FieldTypePresenceDescription and constraints
$objectRootA report column. The amount lists on each row are ordered to match the report's columns.
endDateJSONOptional
endDate (anyOf 1)JSONAlternative
endDate (anyOf 1) (allOf 1)stringAll variants applyFormat: date
endDate (anyOf 1) (allOf 2)JSONAll variants applyThe last day (inclusive) of the column that falls between the Books entries start date and today.
Omitted, along with @startDate@, when no day of the column falls in that window.
endDate (anyOf 2)nullAlternative
isPartialbooleanRequired within parentWhether @startDate@ and @endDate@ cover fewer days than the column's label, because the label extends
before the Books entries start date or after today. Always true when @startDate@ and @endDate@ are omitted.
labelstringRequired within parentThe column's name: @yyyy@ (yearly), @yyyy-Qn@ (quarterly), @yyyy-MM@ (monthly), @yyyy-MM-dd@ (daily),
or @yyyy-MM-dd - yyyy-MM-dd@ when the report is not broken down by period.
startDateJSONOptional
startDate (anyOf 1)JSONAlternative
startDate (anyOf 1) (allOf 1)stringAll variants applyFormat: date
startDate (anyOf 1) (allOf 2)JSONAll variants applyThe first day (inclusive) of the column that falls between the Books entries start date and today.
Omitted, along with @endDate@, when no day of the column falls in that window.
startDate (anyOf 2)nullAlternative
Retrieve a balance sheet — response body — rows item
FieldTypePresenceDescription and constraints
$objectRootA row in an income statement or balance sheet.
amountsarrayRequired within parentThe row's own amount for each column, excluding its children.
amounts[]ModelEach itemExpand Create a product — response body — unit Price value
childrenarrayRequired within parentThe rows nested under this row.
children[]ModelEach itemExpand Retrieve a balance sheet — response body — rows item
debitCreditJSONRequired within parent
debitCredit (allOf 1)stringAll variants applyKnown values: debit, credit
debitCredit (allOf 2)JSONAll variants applyWhether the row's amounts have a natural debit or credit balance.
ledgerIdJSONOptional
ledgerId (anyOf 1)stringAlternativeThe ledger this row represents. Omitted unless @rowKind@ is @ledger@.
Format: base58 (max length 22)
ledgerId (anyOf 2)nullAlternative
namestringRequired within parentThe ledger name, the summary heading, or the name of the calculated metric.
parentIdJSONOptional
parentId (anyOf 1)stringAlternativeThe parent ledger of this row's ledger, if it is nested.
Format: base58 (max length 22)
parentId (anyOf 2)nullAlternative
rowKindJSONRequired within parent
rowKind (allOf 1)stringAll variants applyKnown values: ledger, summary, computed
rowKind (allOf 2)JSONAll variants applyWhat the row represents.
sortCodeJSONOptional
sortCode (anyOf 1)stringAlternativeThe ledger/account number used for chart ordering. Omitted unless @rowKind@ is @ledger@.
sortCode (anyOf 2)nullAlternative
subTypeJSONOptional
subType (anyOf 1)JSONAlternative
subType (anyOf 1) (allOf 1)stringAll variants applyKnown values: currentAssets, nonCurrentAssets, transfersBetweenAccounts, uncategorizedAssets, currentLiabilities, nonCurrentLiabilities, equity, operatingRevenues, otherIncome, costOfGoodsSold, operatingExpenses, otherExpenses, retainedEarnings
subType (anyOf 1) (allOf 2)JSONAll variants applyThe ledger's more specific accounting classification. Omitted unless @rowKind@ is @ledger@.
subType (anyOf 2)nullAlternative
totalAmountsarrayRequired within parentThe row's amount for each column, including all of its children.
totalAmounts[]ModelEach itemExpand Create a product — response body — unit Price value
typeJSONOptional
type (anyOf 1)JSONAlternative
type (anyOf 1) (allOf 1)stringAll variants applyKnown values: asset, liability, equity, revenue, expense
type (anyOf 1) (allOf 2)JSONAll variants applyThe top-level accounting classification of the row's ledger or summary grouping. Omitted on @computed@ rows.
type (anyOf 2)nullAlternative

Referenced models: Create a product — response body — unit Price value, Retrieve a balance sheet — response body — rows item

Retrieve a balance sheet — response body — retained Earnings calculated Current Year Earnings, calculated Retained Earnings calculated Current Year Earnings, calculated Retained Earnings
FieldTypePresenceDescription and constraints
$objectRootSystem-calculated equity amounts that are added to the Retained Earnings and Current Year Earnings ledger rows.
calculatedCurrentYearEarningsarrayRequired within parentFor each column, current-year revenues minus current-year expenses, before journal entries posted to the
Current Year Earnings ledger.
calculatedCurrentYearEarnings[]ModelEach itemExpand Create a product — response body — unit Price value
calculatedRetainedEarningsarrayRequired within parentFor each column, prior-year revenues minus prior-year expenses, before journal entries posted to the
Retained Earnings ledger.
calculatedRetainedEarnings[]ModelEach itemExpand Create a product — response body — unit Price value

Referenced models: Create a product — response body — unit Price value

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]+)?$

SDK function policy ID: mercury.getbooksprofitandloss. Catalog operation: mercury:getBooksProfitAndLoss. 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.