For AI agents: markdown of this page — /docs-content-en/entities/order-statuses/aggregate.md documentation index — /llms.txt

Aggregate order statuses

POST /v1/order-statuses/aggregate

Counts statuses grouped by type or notify. The only numeric field is sort, so numeric functions (sum, avg) are rarely useful — the main scenario is count with a filter or grouping.

Standard fields

All status fields are categorical — suitable only for groupBy and filter:

Field Purpose
Fieldtype PurposeGroup by type: O (order) or D (delivery)
Fieldnotify PurposeGroup by whether a notification is sent

The full list of aggregatable fields is shown in the table above.

Request fields (body)

Parameter Type Required Description
Parameteraggregate Typearray Requiredno DescriptionArray of aggregations. For statuses the main option is count. The numeric functions accept the only numeric field, sort. The count format is { "field": "*", "function": "count" }. Without the parameter — a count of the records matching the filter
Parameterfilter Typeobject Requiredno DescriptionFiltering — the same fields as in GET /v1/order-statuses. Filtering syntax
ParametergroupBy Typestring | string[] Requiredno DescriptionField or array of fields to group by (maximum 5)
ParametergroupOrderBy Typearray Requiredno DescriptionGroup sorting: [{ "field": "count", "direction": "desc" }]
ParametergroupLimit Typenumber Requiredno DescriptionLimit on the number of returned groups (1-1000)

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/order-statuses/aggregate" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "groupBy": "type"
  }'

curl — OAuth application

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/order-statuses/aggregate" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "groupBy": "type"
  }'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/order-statuses/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    groupBy: 'type',
  }),
})

const { success, data } = await res.json()
console.log('Status distribution:', data.groups)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/order-statuses/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    groupBy: 'type',
  }),
})

const { success, data } = await res.json()

Other scenarios

Count records — count with field "*", the fastest request without fetching records. Without the aggregate array the result is the same:

JSON
{ "aggregate": [{ "field": "*", "function": "count" }] }

How many statuses have notifications enabled:

JSON
{
  "filter": { "notify": true }
}

Group by both axes at once:

JSON
{
  "groupBy": ["type", "notify"]
}

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.count Typenumber DescriptionTotal number of statuses matching the filter
Fielddata.aggregates Typeobject DescriptionNumeric aggregation results — for statuses they are computed over sort only; an empty object when no aggregate array is passed
Fielddata.groups Typearray DescriptionGroups (only with groupBy)
Fielddata.meta.totalRecords Typenumber DescriptionTotal number of records
Fielddata.meta.recordsProcessed Typenumber DescriptionNumber of processed records
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 DescriptionNumber of groups before groupLimit
Fielddata.meta.groupsTruncated Typeboolean DescriptionWhether the group list was truncated by groupLimit

Response example

JSON
{
  "success": true,
  "data": {
    "count": 9,
    "aggregates": {},
    "groups": [
      { "type": "O", "count": 6, "aggregates": {} },
      { "type": "D", "count": 3, "aggregates": {} }
    ],
    "meta": {
      "totalRecords": 9,
      "recordsProcessed": 9,
      "truncated": false,
      "groupTotal": 2,
      "groupsTruncated": false
    }
  }
}

Without groupBy, the data.groups field is absent from the response.

Error response example

400 — unknown field in groupBy:

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "groupBy field 'foo' is not aggregatable on this entity. Available: type, notify."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS DescriptionUnknown function or nonexistent field — the message contains a list of allowed fields
HTTP400 CodeINVALID_PARAMS DescriptionMore than 5 fields passed in groupBy
HTTP400 CodeINVALID_PARAMS DescriptionReserved keywords in groupBy: count, aggregates, meta, groups
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the sale 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 general API errors, see Errors.

Known specifics

In practice only count is needed. The only numeric field of a status is sort, and it is the only one the sum / avg / min / max functions accept; for any other field, they return 400 INVALID_PARAMS. To count statuses, use count (without aggregate) with a filter or grouping.

Small data volume. A Bitrix24 account holds only dozens of statuses, so the 5000-record ceiling is never reached for this entity.

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. For full details, see Aggregation POST — the 5000-record ceiling.

See also