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.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
entity | string | Yes | — | Entity code |
year | integer | Yes | — | Fiscal year. Missing, blank, non-integer, boolean or less than 1 fails the item with Invalid year. |
period | string or int | Yes | — | A token of that year's declared calendar: period number or code, Q1..Q4, H1, H2, FY. See epm_value. |
account | string | Yes | — | Main account code |
measure | string | No | the Dataset's default_measure | Must be in the Dataset's measures and Published in the Measure registry |
fact | string | No | — | Dataset fact_name; wins over scenario |
scenario | string | No | actuals | Resolves the Dataset by scenario_key when fact is absent |
dimensions | object | No | {} | 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_id | string | No | "" | One budget scenario, for Datasets with has_scenario_id |
layer | string | No | "" | Budget layer, for Datasets with has_layer |
hierarchy, node / hierarchy_node | string | No | — | 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"]
}
}
| Field | Type | Description |
|---|---|---|
values | array | One value per item, in order. null where the item failed. |
errors | array | Present only when at least one item failed. Same length as values; null for items that succeeded, the message for items that failed. |
error_codes | array | Present 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_dataas#N/A, any other item with an error as#VALUE!with that message, and anullvalue without an error as0.
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.
| Error | Cause |
|---|---|
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 periods | period 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 failed | Applied 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.