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

Aggregate SKUs

POST /v1/catalog-skus/aggregate

Counts the parent products of a product catalog with filtering and grouping by section via groupBy.

The dateCreate, timestampX, dateActiveFrom, and dateActiveTo fields are not accepted in filter: the request returns 400 UNKNOWN_FILTER_FIELD before calling Bitrix24. This endpoint does not support date-range filtering. Calculate aggregates for a specific period in your integration using records from the list endpoint, where these dates are available in select and responses.

Standard fields. One field is available for grouping — iblockSectionId, the catalog section. The numeric functions sum, avg, min, max accept fields of type number, but on a parent product these are identifiers, sort and type, so the primary use case is counting products with count and grouping the results.

Request fields (body)

Parameter Type Required Description
Parameterfilter Typeobject Requiredyes DescriptionFiltering by parent product fields. The iblockId key is required — the product catalog from GET /v1/catalogs. The type key accepts one exact number, 3 or 6.
Filtering syntax
Parameteraggregate Typearray Requiredno DescriptionAggregations: [{ "field": "*", "function": "count" }]. Functions: count, sum, avg, min, max. For count, the field is "*". Without the parameter — count only
ParametergroupBy Typestring | string[] Requiredno DescriptionField or array of fields to group by (up to 5). Allowed value — iblockSectionId

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-skus/aggregate" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "iblockId": 25 },
    "aggregate": [{ "field": "*", "function": "count" }],
    "groupBy": "iblockSectionId"
  }'

curl — OAuth application

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-skus/aggregate" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": { "iblockId": 25 },
    "aggregate": [{ "field": "*", "function": "count" }],
    "groupBy": "iblockSectionId"
  }'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-skus/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { iblockId: 25 },
    aggregate: [{ field: '*', function: 'count' }],
    groupBy: 'iblockSectionId',
  }),
})

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

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-skus/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: { iblockId: 25 },
    aggregate: [{ field: '*', function: 'count' }],
    groupBy: 'iblockSectionId',
  }),
})

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

Other scenarios

The blocks below are request bodies.

Count parent products without grouping — the fastest request, no records are fetched:

JSON
{ "filter": { "iblockId": 25 } }

Count parent products without offers — type equals 6:

JSON
{ "filter": { "iblockId": 25, "type": 6 } }

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.count Typenumber DescriptionTotal number of parent products matching the filter
Fielddata.aggregates Typeobject DescriptionResults of numeric functions by field: { "sort": { "max": 500 } }. Without numeric functions — an empty object
Fielddata.groups Typearray DescriptionGroups — present only with groupBy. Each element: grouping fields + count + aggregates
Fielddata.meta.totalRecords Typenumber DescriptionTotal number of records
Fielddata.meta.recordsProcessed Typenumber DescriptionNumber of processed records (up to 5000). For a request without groupBy and numeric functions — 0
Fielddata.meta.truncated Typeboolean Descriptiontrue when the groups or 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 record shortfall is reported in data.meta.recordsShortfall, and details of the interrupted slice are reported 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. Present only with groupBy
Fielddata.meta.groupsTruncated Typeboolean Descriptiontrue if the number of groups was limited. Present only with groupBy

Response example

JSON
{
  "success": true,
  "data": {
    "count": 14,
    "aggregates": {},
    "groups": [
      { "iblockSectionId": null, "count": 11, "aggregates": {} },
      { "iblockSectionId": 85, "count": 1, "aggregates": {} },
      { "iblockSectionId": 19, "count": 2, "aggregates": {} }
    ],
    "meta": {
      "totalRecords": 14,
      "recordsProcessed": 14,
      "truncated": false,
      "groupTotal": 3,
      "groupsTruncated": false
    }
  }
}

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

Error response example

400 — a field outside the list available for grouping:

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

Errors

HTTP Code Description
HTTP400 CodeMISSING_REQUIRED_FILTER DescriptionThe required filter.iblockId filter was not passed — checked before the Bitrix24 call (an example body is in the message)
HTTP400 CodeUNKNOWN_FILTER_FIELD DescriptionUnknown filter field or a date field: dateCreate, timestampX, dateActiveFrom, dateActiveTo. The message contains the list of available fields
HTTP400 CodeUNSUPPORTED_FILTER DescriptionThe filter.type key was passed as something other than one number, 3 or 6
HTTP400 CodeINVALID_PARAMS DescriptionThe groupBy field is outside the available list — the message lists the allowed ones
HTTP400 CodeINVALID_PARAMS DescriptionA numeric function over a field that is not among the numeric fields of a parent product — the message lists them: Field '<name>' not found. Available numeric fields: ...
HTTP400 CodeINVALID_PARAMS DescriptionUnknown function — Invalid aggregate function '<name>'. Supported: count, sum, avg, min, max
HTTP400 CodeINVALID_PARAMS DescriptionMore than 5 fields passed in groupBy
HTTP422 CodeBITRIX_ERROR DescriptioniblockId points to an offer catalog (productType is not allowed for this catalog)
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the catalog scope
HTTP401 CodeMISSING_API_KEY DescriptionThe X-Api-Key header was not passed
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 is resolved in one request, grouping and numeric functions are not. A request without groupBy and numeric functions is counted in a single call regardless of the size of the result set. With groupBy or the sum, avg, min, max functions, records are loaded page by page — up to 5000 — and counted on the server side. If more than 5000 records match the filter, meta.truncated is true, and the groups and aggregates are built over the first 5000. 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.

See also