Skip to main content

POST epm_batch

Returns many values in one request. This is the endpoint the Excel add-in's =K.EPM(), =K.EPM_BUDGET(), =K.EPM_VARIANCE(), =K.EPM_DEBIT(), =K.EPM_CREDIT() and =K.CF() functions call (konsol/public/excel-addin/functions.js).

Endpoint​

POST /api/method/konsol.api.epm_batch

Declared methods=["POST"]; a GET is refused.

Authentication: logged-in user (session cookie or X-Konsolidat-Token). Entity access is checked per item.

Request​

The raw POST body is a JSON array. Each element is one request object.

FieldTypeRequiredDefaultDescription
entitystringYes—Entity code
yearintegerYes—Fiscal year. Missing, blank, non-integer, boolean or less than 1 fails the item with Invalid year.
periodstring or intYes—A token of that year's declared calendar: period number or code, Q1..Q4, H1, H2, FY. See epm_value.
accountstringYes—Main account code
measurestringNothe Dataset's default_measureMust be in the Dataset's measures and Published in the Measure registry
factstringNo—Dataset fact_name; wins over scenario
scenariostringNoactualsResolves the Dataset by scenario_key when fact is absent
dimensionsobjectNo{}Dimension filters, e.g. {"dim_region":"EU","dim_product":"X"}. Keys must be dimensions declared on the Dataset. This is the only way to filter by dimension: a request key outside this table (such as a top-level dimension name, or the old cost_center / department) is refused for that row with "Unknown request key" (konsol#287).
scenario_idstringNo""One budget scenario, for Datasets with has_scenario_id
layerstringNo""Budget layer, for Datasets with has_layer
hierarchy, node / hierarchy_nodestringNo—A hierarchy read for a Reporting Hierarchy member; see epm_value

Size limit​

At most 2000 items (MAX_BATCH_SIZE). A larger array is refused as a whole with Batch size {n} exceeds maximum of 2000.

Response​

{
"message": {
"values": [125430.50, 0.0, 89200.00, null],
"errors": [null, null, null, "Invalid measure 'foo' for fact 'gl_journal_entries'. Allowed: period_credit, period_debit, period_net_amount, transaction_count, ytd_net_amount"]
}
}
FieldTypeDescription
valuesarrayOne value per item, in order. null where the item failed.
errorsarrayPresent only when at least one item failed. Same length as values; null for items that succeeded, the message for items that failed.
error_codesarrayPresent only when at least one failed item has a code. Same length as values. "no_data" marks an actuals item whose period has no trial balance (konsol#401); other errors have null.
  • A successful item is a float; no matching rows is 0.0.
  • The add-in shows an item with code no_data as #N/A, any other item with an error as #VALUE! with that message, and a null value without an error as 0.

Validation per item​

Each item is validated before any query runs, in this order: year, then period against the year's declared calendar, then for a flat item the Dataset, measure and dimensions and then entity access, or for a hierarchy item the hierarchy and node, then entity access, then the measure. A failed item gets an error; the other items still run.

ErrorCause
Unknown request key ...A key outside the request table above, e.g. a dimension given at the top level instead of in dimensions
Invalid year / Invalid year '{y}'Missing or bad year
text naming the declared periodsperiod not declared for that year
Invalid fact ..., Invalid scenario ..., Fact '{x}' declares no Default Measure ..., Invalid measure ..., Invalid dimension ...Registry validation; see epm_value
No trial balance for {entity} {year} {period} (code no_data)An actuals read of a period with no trial balance. A range reads if one of its periods is loaded; a read across all entities is refused only when no readable entity is loaded. Budget reads are not checked
Not permitted to access entity '{e}'Entity outside the caller's allow-list (per item, not a 403 for the batch)
ClickHouse query timeout, ClickHouse connection failed, ClickHouse query failedApplied to every item in the affected query group

Example​

curl​

curl -X POST "http://localhost:8069/api/method/konsol.api.epm_batch" \
-H "Content-Type: application/json" \
-b "cookies.txt" \
-d '[
{"entity": "USMF", "year": 2024, "period": 5, "account": "401100"},
{"entity": "USMF", "year": 2024, "period": 5, "account": "501100"},
{"entity": "DEMF", "year": 2024, "period": "Q1", "account": "401100", "measure": "period_net_amount"},
{"entity": "USMF", "year": 2025, "period": "FY", "account": "6100", "measure": "period_amount", "fact": "budget_input", "scenario_id": "BUDGET_2025"},
{"entity": "USMF", "year": 2024, "period": 5, "account": "401100", "measure": "variance_abs", "fact": "variance_analysis", "dimensions": {"dim_region": "EU"}}
]'

Python​

import requests

session = requests.Session()
session.post("http://localhost:8069/api/method/login",
json={"usr": "admin", "pwd": "password"})

response = session.post(
"http://localhost:8069/api/method/konsol.api.epm_batch",
json=[
{"entity": "USMF", "year": 2024, "period": 5, "account": "401100"},
{"entity": "USMF", "year": 2024, "period": 5, "account": "501100"},
],
)
data = response.json()["message"]
print(data["values"])

Query grouping​

The batch does not run one query per item. Flat items are grouped by:

(dataset, measure, set of dimension names, scenario_id, layer)

Each group is one ClickHouse SELECT with parameterised IN (...) lists for entities, years, accounts and periods; fiscal_period is selected and grouped so each cell is given the sum of its own periods. The period is deliberately not part of the key (konsol#231): twelve monthly cells for the same accounts are one query, not twelve. Hierarchy items are grouped separately by konsol.hierarchy_query.batch_query_hierarchy.

The Frappe-to-ClickHouse request has a 30-second timeout.