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

Site aggregation

POST /v1/sites/aggregate

Counts sites matching a filter and groups them by categorical fields. Supports the count function, groupBy grouping and the numeric functions sum/avg/min/max over fields of type number.

Request fields (body)

Parameter Type Required Description
Parameteraggregate Typearray Requiredno DescriptionArray of aggregations. For sites, the meaningful aggregation is { "field": "*", "function": "count" }. The sum/avg/min/max functions accept fields of type number, but on a site those are identifiers (id, tplId, domainId, version and others), not metrics. Without this parameter, the count of records matching the filter is returned
ParametergroupBy Typestring | array Requiredno DescriptionField or fields to group by. Only fields from aggregatable are allowed: type, active, deleted, lang, tplId, domainId, createdById, modifiedById. Up to 5 fields
ParametergroupOrderBy Typearray Requiredno DescriptionGroup sorting: an array of { "field": "count" | "<dimension>", "direction": "asc" | "desc" }. Works only together with groupBy
ParametergroupLimit Typenumber Requiredno DescriptionLimit on the number of returned groups (1..1000). Works only together with groupBy
Parameterfilter Typeobject Requiredno DescriptionFiltering by the fields from GET /v1/sites/fields.
Filtering syntax
Parameterscope Typestring Requiredno DescriptionInternal landing area: KNOWLEDGE / GROUP / MAINPAGE. Without this parameter, regular landing sites are counted

Type filter and area (scope). If you pass {"filter": {"type": "KNOWLEDGE"}} or "GROUP" without scope, Vibecode supplies the matching area itself (type=KNOWLEDGE → scope=KNOWLEDGE) — counting knowledge bases and group pages works without setting scope manually, the same way it does in list and search. An explicit scope wins. MAINPAGE is an area, not a site type (its sites have type VIBE), so it is not derived from the type filter: pass scope=MAINPAGE explicitly for home pages.

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/sites/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/sites/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/sites/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('Sites by type:', data.groups)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/sites/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

Total number of sites in the Bitrix24 account — the fastest request, without fetching records:

JSON
{}

Number of active landing sites:

JSON
{ "filter": { "type": "PAGE", "active": true } }

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.count Typenumber DescriptionNumber of sites matching the filter
Fielddata.aggregates Typeobject DescriptionNumeric aggregation results — over fields of type number (on a site those are identifiers, for example tplId). An empty object when no aggregate array is passed
Fielddata.groups Typearray DescriptionPresent when groupBy is set. Each element is a dimension value plus the count of records in the group
Fielddata.meta.totalRecords Typenumber DescriptionTotal number of records
Fielddata.meta.recordsProcessed Typenumber DescriptionHow many records were 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.recordsShortfall Typenumber DescriptionPresent with truncated: true when fewer records were read than data.count promised: how many records were left out of the calculation
Fielddata.meta.pageErrorSample Typeobject DescriptionPresent with truncated: true when the slice was cut short by a sub-page error: the code and message of that error
Fielddata.meta.warnings Typearray DescriptionPresent with truncated: true: a warning with the AGGREGATE_TRUNCATED code and a message
Fielddata.meta.groupTotal Typenumber DescriptionPresent when groupBy is set — the number of groups
Fielddata.meta.groupsTruncated Typeboolean DescriptionPresent when groupBy is set. true if the number of groups exceeded the limit and the list was truncated

Response example

Grouping by type (groupBy: "type"):

JSON
{
  "success": true,
  "data": {
    "count": 18,
    "aggregates": {},
    "groups": [
      { "type": "PAGE", "count": 11, "aggregates": {} },
      { "type": "STORE", "count": 5, "aggregates": {} },
      { "type": "VIBE", "count": 2, "aggregates": {} }
    ],
    "meta": {
      "totalRecords": 18,
      "recordsProcessed": 18,
      "truncated": false,
      "groupTotal": 3,
      "groupsTruncated": false
    }
  }
}

Plain count without grouping ({}):

JSON
{
  "success": true,
  "data": {
    "count": 18,
    "aggregates": {},
    "meta": {
      "totalRecords": 18,
      "recordsProcessed": 0,
      "truncated": false
    }
  }
}

Error response example

400 — a field outside the aggregatable list:

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "groupBy field 'title' is not aggregatable on this entity. Available: type, active, deleted, lang, tplId, domainId, createdById, modifiedById."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS DescriptionThe groupBy field is outside the aggregatable list, or an unknown aggregation function
HTTP403 CodeSCOPE_DENIED DescriptionThe API key lacks the landing scope
HTTP401 CodeTOKEN_MISSING DescriptionThe API key has no configured tokens
HTTP409 CodeLANDING_MODULE_NOT_ENABLED DescriptionThe Sites module is unavailable on this Bitrix24 account. Ask a Bitrix24 account administrator to enable it — until then, retrying the request returns the same error
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

Grouping is computed over the records that were read. When a response arrives with meta.truncated: true, the group counts are computed over the slice that was read, while the top-level count stays the exact total for the filter.

Visibility by user permissions. Only sites the API key owner has "view" permission for are counted. If you expect a non-zero result but count is zero, check the permissions of the user the key is issued for.

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