Query Endpoint
Run an aggregation query over a model. An aggregation query computes measures — totals, averages, counts, distributions — over the rows of a model, optionally grouped into segments.
Method: POST
Path: /data/{model}/query
Content-Type: application/json
Accept: application/json
Authentication: Required
Every property is written fully qualified, as dataset.property — orders.revenue,
customers.country. One request can combine properties of any datasets the model links: you never
choose a starting dataset, Engeene finds the one the others are reached from. See
Cross-Dataset Analysis.
The TypeScript client builds this request, translates filter values and labels the result for you — and can send many queries in one request. Prefer it over hand-written JSON.
A first query
Total revenue:
curl -X POST "https://{workspace}.{region}.engeene.com/data/ecommerce/query" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"metrics": [{"property": "orders.revenue", "aggregation": "Sum"}]}'
Request body
{
"metrics": [
{ "property": "orders.revenue", "aggregation": "Sum" },
{ "property": "orders.orderId", "aggregation": "Count" },
{ "property": "orders.latency", "aggregation": "Percentile", "percentile": 95 }
],
"conditions": [
{ "type": "Time In Range", "property": "orders.orderedAt", "minimum": 1709251200000, "maximum": 1711929600000 },
{ "type": "Attribute In", "property": "customers.country", "shortIds": [1, 5] }
],
"segmentBy": ["orders.category"],
"orderBy": { "metricIndex": 0, "direction": "Descending" },
"segmentLimit": 10,
"includeOther": true
}
| Field | Required | Type | Description |
|---|---|---|---|
metrics |
Yes | Array | One or more measures |
conditions |
No | Array | Filters, all of which must match |
segmentBy |
No | Array | Properties to group by, as dataset.property — see Segmentation and Top-N |
segmentBuckets |
No | Object | Range size per measure in segmentBy ({"orders.revenue": 10000}) — see By numeric range |
timeSegments |
No | Array | Group by a time property by a calendar period — { "property": "orders.orderedAt", "grouping": "MONTH", "timezone": "Europe/Prague" }; timezone is optional (UTC). See By time period |
dropNullSegments |
No | Boolean | true leaves out groups in which no measure has a value (default false) |
orderBy |
No | Object | Rank groups by a measure, by an attribute's value or by a time segment's period — see Ordering segments |
segmentLimit |
No | Number | How many groups to return |
includeOther |
No | Boolean | Add one "Other" row for the groups outside segmentLimit |
segmentFilters |
No | Array | Keep only the groups whose aggregated value is in a range — {"type": "Metric In Range", "metricIndex": 0, "minimum": 1000}; "Metric Not In Range" keeps the outside. metricIndex is the position in metrics; minimum / maximum are in the units the answer shows (not scaled like Measure In Range); minInclusive / maxInclusive default to true. Decided before orderBy / segmentLimit / includeOther; a group with no value is never kept; the totals still cover every matching row. Needs segmentBy or timeSegments — see Filtering by a measure's value |
primaryDataset |
No | String | Rarely needed. Pins the dataset the query starts from; naming a parent dataset lists every parent — see Parent rows with child aggregates |
Measure
| Field | Required | Type | Description |
|---|---|---|---|
property |
Yes | String | The property to aggregate, as dataset.property. The keys column and measure are refused with 400 INVALID_REQUEST naming property |
aggregation |
Yes | String | One of the aggregations. Case-sensitive |
percentile |
For Percentile |
Number | Rank, 0–100 |
label |
No | String | Display label |
conditions |
No | Array | Filters that apply to this measure only |
grouping |
No | String | On a Count of a time property: count distinct periods of this grouping (DAY, WEEK, MONTH, …) instead of distinct moments |
timezone |
No | String | With grouping: the IANA zone the periods are read in. Default: the zone of the first timeSegments entry, else UTC |
subAggregations |
No | Array | Levels of a second aggregation — see An aggregation of an aggregation |
A measure can name a property of any dataset the model links — Engeene follows the references:
{
"metrics": [
{ "property": "orders.revenue", "aggregation": "Sum" },
{ "property": "customers.lifetimeValue", "aggregation": "Average" }
]
}
A computed measure derives a value from other measures — revenue per order from a Sum and a Count:
{
"metrics": [
{ "property": "orders.revenue", "aggregation": "Sum" },
{ "property": "orders.orderId", "aggregation": "Count" },
{ "type": "Computed", "expression": "$0 / $1", "label": "Revenue per Order" }
]
}
The expression language and the $N positions are in Computed Measures.
An aggregation of an aggregation
Some questions have two levels of arithmetic in them: "how many items were sold each day, averaged
over the sales people?" is a count first and an average second. A sub-aggregation adds that
second level to a measure: subAggregations groups the measure by one more property underneath the
request's own segments, then combines those groups back into one value with an aggregation you
choose. In Explore it is Add Sub-Aggregation — see
Measures → Sub-aggregations.
{
"metrics": [
{
"property": "sales.itemId",
"aggregation": "Count",
"subAggregations": [{ "property": "sales.salesPerson", "aggregation": "Average" }]
}
],
"timeSegments": [{ "property": "sales.soldAt", "grouping": "DAY", "timezone": "Europe/Prague" }]
}
Each day's value is the average, across the sales people, of how many distinct items each one sold that day.
| Level field | Required | Type | Description |
|---|---|---|---|
property |
One of the two | String | The property to group by, as dataset.property |
properties |
One of the two | Array | Several properties forming one group, combined back in a single step. Never beside property |
grouping |
For a time property | String | The period to group a time property by (DAY, WEEK, MONTH, …) |
timezone |
No | String | With grouping: the IANA zone the periods are read in (default UTC) |
aggregation |
Yes | String | How the groups are combined: Sum, Average, Minimum, Maximum, Count or Median |
The list is ordered outermost first: the measure's own aggregation is calculated on the smallest groups, then the last level combines them, then the one before it, and the first level last.
Grouping by a pair is not the same as two levels. Two levels — by region, then by sales person — average the per-region averages. One level over both properties averages every (region, sales person) pair directly; the two are different numbers whenever the regions have different numbers of people:
{
"metrics": [
{
"property": "sales.amount",
"aggregation": "Sum",
"subAggregations": [{ "properties": ["sales.region", "sales.salesPerson"], "aggregation": "Average" }]
}
]
}
Rules — each broken one is refused with 400 INVALID_REQUEST naming what is wrong:
- At most three levels and four grouping properties per measure, counted across all its levels.
- What a level groups by: an attribute with one value per row, or a time property with a
grouping. Not a measure, and not a multi-value property — one row can carry several of its values, so its groups overlap and the row would be counted more than once. - Not a property the request already groups by (a
segmentByentry, or atimeSegmentsentry with the same period and time zone), and no property twice within one measure — across levels or inside one level'sproperties. - A level's
Countcounts the groups it combines that have a value — how many sales people, regions or days the level produced. - Not on a computed measure, and not on
Range,RatioorCoefficient Of Variation, which are already built out of several numbers. - Not with
includeOther.segmentLimitandorderBywork.
A group with no value is skipped, so an empty group never drags an average down. When no group has
a value the result has no value — except under a Count level, which reads 0. The total over all
matching rows (metrics in the response) is calculated the same way over every row, never by
combining the per-segment values. Every result is exact.
Aggregations
| Aggregation | Result | Works on |
|---|---|---|
Sum |
Sum of all values | Measure |
Count |
Number of distinct values. Count a dataset's ID property to get its number of rows | Attribute, ID, Reference |
Minimum |
Smallest value | Measure |
Maximum |
Largest value | Measure |
Average |
Arithmetic mean | Measure |
Median |
Middle value | Measure |
Percentile |
Value at a rank from 0 to 100, given in percentile |
Measure |
Variance |
Population variance, with twice the measure's decimals (at most 9). A variance too large to return is an error, never a capped number — ask for Standard Deviation |
Measure |
Standard Deviation |
Population standard deviation, with the measure's decimals | Measure |
Sample Variance |
Sample variance; decimals as for Variance |
Measure |
Sample Standard Deviation |
Sample standard deviation; decimals as for Standard Deviation |
Measure |
Range |
Maximum minus minimum | Measure |
Ratio |
Each group's share of the total — its sum divided by the grand total; empty when the total is zero | Measure |
Coefficient Of Variation |
Standard deviation relative to the mean; empty when the mean is zero | Measure |
Names are spelled exactly as shown — Title Case, with spaces. Every result is exact: no sampling, no approximation.
On a time property
A time property takes exactly three aggregations; any other is 400 INVALID_REQUEST naming the property.
| Aggregation | Result |
|---|---|
Minimum |
The earliest moment, in epoch milliseconds (UTC). Empty when the group has no time |
Maximum |
The latest moment, in epoch milliseconds (UTC). Empty when the group has no time |
Count |
The number of distinct moments (to the minute) — or, with grouping, of distinct periods read in timezone. Never empty: a group with no time counts 0 |
{
"metrics": [
{ "property": "orders.placedAt", "aggregation": "Maximum" },
{ "property": "orders.placedAt", "aggregation": "Count", "grouping": "DAY", "timezone": "Europe/Prague" }
],
"segmentBy": ["orders.channel"]
}
grouping on Minimum / Maximum, subAggregations on a time measure, and a computed measure reading
an earliest or latest moment are refused with 400. A Count of a time property may be read by a
computed measure. includeOther works when every measure of the query is a time measure.
Conditions
type is Title Case with spaces: Attribute In, Attribute Not In, Measure In Range,
Measure Is Null, Measure Is Not Null, Time In Range, Time Not In Range, Time Is Null,
Time Is Not Null, Cyclic Time In and
Semi Join. Each is described in Filtering. An attribute condition takes value
identifiers in shortIds — get them from
POST /attributes/lookup. 0 stands for "no value"
(Rows with no value).
A condition on a dataset other than the one the query starts from — customers.segment on an orders
query — is applied through the reference between them; write it like any other.
Response
{
"matchingRows": 18234,
"segmentKeyLength": 1,
"metricScales": [100, 1],
"metrics": [4829950, 18234],
"segments": [
{ "key": [17], "metrics": [1830075, 6012] },
{ "key": [4], "metrics": [1204410, 4377] },
{ "key": [9007199254740990], "metrics": [1795465, 7845] }
]
}
| Field | Description |
|---|---|
matchingRows |
Rows that matched the conditions |
metricScales |
One per measure. Values are whole numbers — divide each by its scale. A count has scale 1; Sum, Minimum, Maximum, Average, Median, Percentile and Standard Deviation have the scale of the property they aggregate; a Variance has twice that property's decimals, at most 9 |
metrics |
The totals over all matching rows, one per measure |
metricNulls |
When present: true where a total has no value (no row contributed one). The number beside it is then meaningless. A Count always has a value — 0 when nothing matched |
segmentKeyLength |
How many values each group key has — one per segmentBy entry, then one per timeSegments entry |
segments[] |
One entry per group: its key, its metrics, and nulls with the same meaning as metricNulls |
In the example, revenue (scale 100) is 48,299.50 across 18,234 orders, and 9007199254740990 is the
"Other" row.
The order of segments[] is not defined unless you ask for one. Without orderBy (or a value
order — see Ordering segments), the groups come back
in no particular order, and the same request may list them differently from one call to the next.
Read a group by its key, or ask for the order you need.
Reading a group key
Each position of key follows the request's segmentBy entries, then its timeSegments:
| Grouped by | The key value is |
|---|---|
| An attribute | The value's identifier — turn it into text with /attributes/resolve; 0 is "no value" |
| A measure range | The range number: the range starts at key × range size, in the measure's stored units |
YEAR |
The year |
QUARTER / MONTH |
Quarters / months since year 0: year × 4 + quarter (0–3), year × 12 + month (0–11) |
DAY / HOUR |
Days / hours since 1 January 1970, counted in the request's time zone |
HOUR_OF_DAY, DAY_OF_WEEK, WEEK_OF_YEAR, MONTH_OF_YEAR, QUARTER_OF_YEAR |
The hour (0–23), weekday (1 = Monday … 7), week (1–53), month (1–12) or quarter (1–4) |
Two special values appear in any position: 9007199254740991 is Unknown (a reference to a
record that does not exist, a row with no time, a measure with no value) and 9007199254740990 is
the Other row.
Large numbers
A value is exact up to 9223372036854775807 units of its scale; a Variance larger than that is
refused with 422 rather than capped — ask for Standard Deviation, which always fits. JavaScript
holds whole numbers exactly only up to 9007199254740991: read the JSON with a parser that keeps
64-bit integers if a value can be larger, or its last digits come back as zeros.
Status codes
| Status | Meaning |
|---|---|
200 |
Success |
400 |
Invalid query — no measures, an unknown property, invalid JSON, a retired key |
401 |
Missing or invalid token |
404 |
Model not found |
408 |
The server was busy and could not start the query in time — retry |
422 |
Too expensive to answer as asked — add filters or narrow the time range. Also a Variance too large to return |
429 |
Too many requests — retry after Retry-After |
Error bodies and codes: API Reference → Errors.
Examples
Several measures
{
"metrics": [
{ "property": "orders.revenue", "aggregation": "Sum" },
{ "property": "orders.orderId", "aggregation": "Count" },
{ "property": "orders.revenue", "aggregation": "Average" },
{ "property": "orders.latency", "aggregation": "Percentile", "percentile": 95 }
]
}
Revenue in March 2024
{
"conditions": [
{ "type": "Time In Range", "property": "orders.orderedAt", "minimum": 1709251200000, "maximum": 1711929600000 }
],
"metrics": [{ "property": "orders.revenue", "aggregation": "Sum" }]
}
Revenue by customer country, top 5 plus Other
{
"metrics": [{ "property": "orders.revenue", "aggregation": "Sum" }],
"segmentBy": ["customers.country"],
"orderBy": { "metricIndex": 0, "direction": "Descending" },
"segmentLimit": 5,
"includeOther": true
}
Orders per revenue range of 10,000
{
"metrics": [{ "property": "orders.orderId", "aggregation": "Count" }],
"segmentBy": ["orders.revenue"],
"segmentBuckets": { "orders.revenue": 10000 }
}
Parent rows with child aggregates
An ordinary query starts from the rows that hold the numbers, so a customer with no orders never
appears. To list every row of a parent dataset — one that other datasets reference — with
aggregates over its children, name the parent in primaryDataset and add the child measures:
{
"primaryDataset": "companies",
"segmentBy": ["companies.industry"],
"metrics": [
{ "property": "companies.employeeCount", "aggregation": "Sum" },
{ "property": "bookings.total", "aggregation": "Sum" },
{ "property": "bookings.bookingId", "aggregation": "Count" }
]
}
Here bookings reaches companies through customers; a child may reference the parent directly or
through other datasets.
- Every parent appears. One with no children shows
0forCountand no value for every other aggregation — as does one whose children are all excluded by a per-measure filter. - A measure on the parent itself is computed over the parent rows once, not multiplied by the number of children.
- A child row that belongs to no parent — its reference is empty, or points at a record that does
not exist, anywhere along the chain — is counted in no row and in no total. On a very large parent
dataset, leaving such rows out can exceed a limit and the request is refused with
422; filter the parent, or repair the references. - Grouping by time works on a time property of the parent, or of a dataset the parent references:
"timeSegments": [{ "property": "companies.registeredAt", "grouping": "MONTH" }]lists every company under its own registration month — those with no children included — and each child row counts under its parent's month. A parent with no time has its own group. A time property of a child is refused with400: one parent would then fall under many times. - Rules:
segmentByandconditionsname properties of the parent; to filter children, put the condition on the child measure. Grouping by a child's property, conditions on another dataset and computed measures are refused with400, and so areorderByandsegmentLimit— the error names the field; sort and trim the rows yourself. A measure on a dataset the parent itself references (rather than one that references the parent) makes the request an ordinary query.
Tips
- Filter by time on the dataset's primary time whenever you can — it is the most effective way to keep a query fast.
Median,PercentileandCountlook at every individual value, so over very large ranges they cost more thanSum,MinimumorMaximum.- Repeated questions are answered instantly.