For AI agents: markdown of this page — /docs-content-en/entities/tasks/aggregate.md documentation index — /llms.txt
Aggregate tasks
POST /v1/tasks/aggregate
Count tasks with filtering and grouping. Numeric functions work on numeric task fields and on user fields of suitable types.
Standard fields:
status— task status (forgroupBy; numeric functions make no sense here — it is a categorical code).groupBy: "status"groups by the actual stored status — thestatusfield value in the response, not the virtual meta-axis offilter[status]priority— priority (forgroupBy)responsibleId— responsible person (forgroupBy; an identifier)groupId— workgroup (forgroupBy; an identifier)
All standard aggregatable fields are identifiers or categorical codes, so count and groupBy work on them. For numeric functions (sum/avg/min/max), suitable built-in candidates are timeEstimate (effort estimate in seconds), timeSpentInLogs (time actually spent, in seconds), or user fields. Those two fields are not accepted in groupBy — among the built-in ones, only the four listed above are available there.
Narrowing the result set by status. To count only open/completed tasks, add
realStatus(the actual status) tofilter:{"filter": {"realStatus": 2}}.filter[status]here is also virtual (the−1/−2/−3meta-axis), not the number from the response.realStatusitself isfilter/sortonly — it is not agroupBydimension: to break down by status usegroupBy: "status"(which groups by the actual status, see above).
User fields (UF): UF fields of types integer, double, money — for numeric functions; UF fields of any type — for groupBy. The full list of UF fields for a specific Bitrix24 account is returned in the INVALID_PARAMS error text if you pass a non-existent name.
Request fields (body)
| Parameter | Type | Required | Description |
|---|---|---|---|
Parameteraggregate |
Typearray | Requiredno | DescriptionArray of aggregations. Each element: { "field": "timeEstimate", "function": "sum" }. Functions: count, sum, avg, min, max. For count, the field is "*". Without the parameter — only count |
Parameterfilter |
Typeobject | Requiredno | DescriptionFiltering by GET /v1/tasks/fields fields.Filtering syntax. Example: {"responsibleId": 1} |
ParametergroupBy |
Typestring | string[] | Requiredno | DescriptionField or array of fields to group by (maximum 5). Accepts UF fields of any type |
Examples
curl — personal key
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/aggregate" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"aggregate": [
{ "field": "timeEstimate", "function": "sum" }
],
"groupBy": "status"
}'
curl — OAuth application
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/aggregate" \
-H "X-Api-Key: YOUR_APP_KEY" \
-H "Authorization: Bearer USER_SESSION_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"aggregate": [
{ "field": "timeEstimate", "function": "sum" }
],
"groupBy": "status"
}'
JavaScript — personal key
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/aggregate', {
method: 'POST',
headers: {
'X-Api-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
aggregate: [{ field: 'timeEstimate', function: 'sum' }],
groupBy: 'status',
}),
})
const { success, data } = await res.json()
console.log('Total tasks:', data.count)
console.log('By status:', data.groups)
JavaScript — OAuth application
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/aggregate', {
method: 'POST',
headers: {
'X-Api-Key': 'YOUR_APP_KEY',
'Authorization': 'Bearer USER_SESSION_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({
aggregate: [{ field: 'timeEstimate', function: 'sum' }],
groupBy: 'status',
}),
})
const { success, data } = await res.json()
To group by several fields, pass an array:
"groupBy": ["status", "responsibleId"](maximum 5).
Other scenarios
Count records — count with field "*", the fastest request without fetching records. Without the aggregate array the result is the same:
{ "aggregate": [{ "field": "*", "function": "count" }] }
How many tasks each responsible person has:
{ "groupBy": "responsibleId" }
Sum over a numeric UF field, broken down by priority:
{
"aggregate": [{ "field": "UF_CRM_TASK_BUDGET", "function": "sum" }],
"groupBy": "priority"
}
Response fields
| Field | Type | Description |
|---|---|---|
Fieldsuccess |
Typeboolean | DescriptionAlways true on success |
Fielddata.count |
Typenumber | DescriptionNumber of records matching the filter |
Fielddata.aggregates |
Typeobject | DescriptionAggregation results. Without aggregate — an empty object |
Fielddata.groups |
Typearray | DescriptionGroups (only with groupBy). Each element: grouping fields + count + aggregates |
Fielddata.meta.totalRecords |
Typenumber | DescriptionTotal number of records |
Fielddata.meta.recordsProcessed |
Typenumber | DescriptionHow many records were actually processed |
Fielddata.meta.truncated |
Typeboolean | Descriptiontrue when the numbers were computed over only some of the records that match the filter: fewer records were read than data.count promised — including when more than 5000 matched the filter — or the slice was cut short by a sub-page error. The size of the gap is reported in data.meta.recordsShortfall, the interrupted slice in data.meta.pageErrorSample. Always present, and false on a complete response. If the request has neither groupBy nor a numeric function, no records are fetched and the flag is always false |
Fielddata.meta.groupTotal |
Typenumber | DescriptionTotal number of groups (only with groupBy) |
Fielddata.meta.groupsTruncated |
Typeboolean | DescriptionWhether the group list was limited by groupLimit |
Response example
Response to the main request (aggregate: [{field: "timeEstimate", function: "sum"}] + groupBy: "status"):
{
"success": true,
"data": {
"count": 599,
"aggregates": {
"timeEstimate": { "sum": 54000 }
},
"groups": [
{ "status": 2, "count": 247, "aggregates": { "timeEstimate": { "sum": 18000 } } },
{ "status": 5, "count": 341, "aggregates": { "timeEstimate": { "sum": 32400 } } },
{ "status": 3, "count": 7, "aggregates": { "timeEstimate": { "sum": 2400 } } },
{ "status": 4, "count": 4, "aggregates": { "timeEstimate": { "sum": 1200 } } }
],
"meta": {
"totalRecords": 599,
"recordsProcessed": 599,
"truncated": false,
"groupTotal": 4,
"groupsTruncated": false
}
}
}
Without groupBy, the data.groups field is absent from the response.
Error response example
400 — non-existent field:
{
"success": false,
"error": {
"code": "INVALID_PARAMS",
"message": "Unknown field 'noSuchField'. Available: status, priority, responsibleId, groupId, UF_CRM_TASK_BUDGET, …"
}
}
Errors
| HTTP | Code | Description |
|---|---|---|
| HTTP400 | CodeINVALID_PARAMS |
DescriptionUnknown function or non-existent field — the message contains the list of allowed fields (standard + UF) |
| HTTP400 | CodeINVALID_PARAMS |
DescriptionA non-numeric UF field (string, enumeration, date) in sum/avg/min/max — the message names the type |
| HTTP400 | CodeINVALID_PARAMS |
DescriptiongroupBy on a standard field outside the aggregatable list |
| HTTP400 | CodeINVALID_PARAMS |
DescriptionMore than 5 fields in groupBy |
| HTTP400 | CodeINVALID_PARAMS |
DescriptionReserved keywords in groupBy: count, aggregates, meta, groups |
| HTTP403 | CodeSCOPE_DENIED |
DescriptionThe API key does not have the tasks scope |
| HTTP401 | CodeTOKEN_MISSING |
DescriptionThe API key has no configured tokens |
| HTTP429 | CodeRATE_LIMITED |
DescriptionRate limit exceeded: 300 requests per minute per portal. All API keys of the portal share one limit. The current limit is returned in the x-ratelimit-limit header. Retry after the delay in the Retry-After header |
For the full list of common API errors, see Errors.
Known specifics
count vs numeric functions. count is computed in a single call and works at any volume. sum/avg/min/max load records page by page (maximum 5000) and compute on the API side. For result sets over 5000 — meta.truncated: true, aggregation over the first 5000. For exact counters on large result sets, use count or narrow the filter. The ceiling is not the only reason for this marker: it also appears when fewer records were read than data.count promised, and the size of the gap is reported in data.meta.recordsShortfall.
The truncation marker travels with the number itself. When a response arrives with meta.truncated: true, the marker truncated: true sits inside every field object in data.aggregates and on every element of data.groups, and data.meta.warnings gains a warning with the code AGGREGATE_TRUNCATED. A client that reads only the number itself therefore sees that it was computed over only some of the records. None of these markers appear on a complete response. Full details — Aggregation POST — the 5000-record ceiling.