[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fcatalog-offers\u002Faggregate":3,"docs-tabs-entities\u002Fcatalog-offers\u002Faggregate":6},{"content":4,"lastmod":5},"\n## Aggregate offers\n\n`POST \u002Fv1\u002Fcatalog-offers\u002Faggregate`\n\nCounts product offers and aggregates their numeric fields — sum, average, minimum and maximum — with filtering and grouping.\n\n**Fields available for aggregation:**\n\n- `purchasingPrice` — purchase price, suitable for numeric aggregation\n- `quantity` — stock balance, suitable for numeric aggregation\n- `iblockSectionId` — catalog section, for `groupBy`\n\n## Request fields (body)\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `filter` | object | yes | Filtering by the fields of [`GET \u002Fv1\u002Fcatalog-offers\u002Ffields`](.\u002Ffields.md). The `iblockId` key is required — the offer catalog ID from [`GET \u002Fv1\u002Fcatalogs`](\u002Fdocs\u002Fentities\u002Fcatalogs). `parentId` selects the offers of one parent product; `type` accepts one exact value: `4` or `5`. The date fields `dateCreate`, `timestampX`, `dateActiveFrom`, and `dateActiveTo` are not accepted: the Bitrix24 method does not apply date filters, and the request is rejected with `400 UNKNOWN_FILTER_FIELD`.\u003Cbr>[Filtering syntax](\u002Fdocs\u002Ffiltering) |\n| `aggregate` | array | no | Aggregations: `[{ \"field\": \"purchasingPrice\", \"function\": \"sum\" }]`. Functions: `sum`, `avg`, `min`, `max`, `count`. For `count`, the field is `\"*\"`. Without the parameter — `count` only |\n| `groupBy` | string \\| string[] | no | Field or array of fields to group by (up to 5). Values — from the list above |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcatalog-offers\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"filter\": { \"iblockId\": 27, \"parentId\": 7189 },\n    \"aggregate\": [\n      { \"field\": \"purchasingPrice\", \"function\": \"sum\" },\n      { \"field\": \"purchasingPrice\", \"function\": \"avg\" }\n    ],\n    \"groupBy\": \"iblockSectionId\"\n  }'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcatalog-offers\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"filter\": { \"iblockId\": 27, \"parentId\": 7189 },\n    \"aggregate\": [\n      { \"field\": \"purchasingPrice\", \"function\": \"sum\" },\n      { \"field\": \"purchasingPrice\", \"function\": \"avg\" }\n    ],\n    \"groupBy\": \"iblockSectionId\"\n  }'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcatalog-offers\u002Faggregate', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    filter: { iblockId: 27, parentId: 7189 },\n    aggregate: [\n      { field: 'purchasingPrice', function: 'sum' },\n      { field: 'purchasingPrice', function: 'avg' },\n    ],\n    groupBy: 'iblockSectionId',\n  }),\n})\n\nconst { success, data } = await res.json()\nconsole.log(data.groups)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcatalog-offers\u002Faggregate', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    filter: { iblockId: 27, parentId: 7189 },\n    aggregate: [\n      { field: 'purchasingPrice', function: 'sum' },\n      { field: 'purchasingPrice', function: 'avg' },\n    ],\n    groupBy: 'iblockSectionId',\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\nTo group by several fields, pass an array: `\"groupBy\": [\"iblockSectionId\", \"quantity\"]`, up to 5 fields.\n\n## Other scenarios\n\nThe blocks below are request bodies.\n\nNumber of offers in a catalog — a body without `aggregate`, the fastest request, with no records fetched. The `iblockId` filter is required here too:\n\n```json\n{ \"filter\": { \"iblockId\": 27 } }\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.count` | number | Total number of offers matching the filter |\n| `data.aggregates` | object | Aggregation results: `{ \"purchasingPrice\": { \"sum\": 0, \"avg\": 0 } }`. Without numeric functions — an empty object |\n| `data.groups` | array | Groups — present only with `groupBy`. Each element: grouping fields + `count` + `aggregates` |\n| `data.meta.totalRecords` | number | Total number of records |\n| `data.meta.recordsProcessed` | number | Number of processed records (up to 5000). For a request without numeric functions or `groupBy` — `0` |\n| `data.meta.truncated` | boolean | `true` 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` |\n| `data.meta.groupTotal` | number | Number of groups. Present only with `groupBy` |\n| `data.meta.groupsTruncated` | boolean | `true` if the number of groups was limited. Present only with `groupBy` |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"count\": 2,\n    \"aggregates\": {\n      \"purchasingPrice\": { \"sum\": 940, \"avg\": 470 }\n    },\n    \"groups\": [\n      {\n        \"iblockSectionId\": null,\n        \"count\": 2,\n        \"aggregates\": { \"purchasingPrice\": { \"sum\": 940, \"avg\": 470 } }\n      }\n    ],\n    \"meta\": {\n      \"totalRecords\": 2,\n      \"recordsProcessed\": 2,\n      \"truncated\": false,\n      \"groupTotal\": 1,\n      \"groupsTruncated\": false\n    }\n  }\n}\n```\n\nWithout `groupBy`, the `data.groups` field is absent from the response.\n\n## Error response example\n\n400 — a field outside the list available for aggregation:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"groupBy field 'nonexistent' is not aggregatable on this entity. Available: purchasingPrice, quantity, iblockSectionId.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `MISSING_REQUIRED_FILTER` | The required filter `filter.iblockId` was not passed — checked before the Bitrix24 call; the message contains an example body |\n| 400 | `UNSUPPORTED_FILTER` | `filter.type` received a value other than `4` and `5`, an array, or an operator |\n| 400 | `INVALID_PARAMS` | The `groupBy` field is outside the available list — the message lists the allowed ones |\n| 400 | `INVALID_PARAMS` | A numeric function over an unknown field — `Field '\u003Cname>' not found. Available numeric fields: ...` |\n| 400 | `INVALID_PARAMS` | More than 5 fields passed in `groupBy` |\n| 403 | `SCOPE_DENIED` | The API key does not have the `catalog` scope |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header was not passed |\n| 429 | `RATE_LIMITED` | Rate 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 |\n\nFor the full list of common API errors, see [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**`count` is resolved in one request. Numeric functions are not.** `count` is computed in a single call regardless of the size of the result set. The `sum`, `avg`, `min`, `max` functions and `groupBy` load records page by page — up to 5000 — and compute the values on the server side. If more than 5000 records match the filter, `meta.truncated` is `true`, and the aggregates and groups 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`.\n\n**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](\u002Fdocs\u002Fentity-api#aggregation-post-the-5000-record-ceiling).\n\n## See also\n\n- [List offers](\u002Fdocs\u002Fentities\u002Fcatalog-offers\u002Flist)\n- [Search offers](\u002Fdocs\u002Fentities\u002Fcatalog-offers\u002Fsearch)\n- [Offer fields](\u002Fdocs\u002Fentities\u002Fcatalog-offers\u002Ffields)\n- [Catalog SKUs](\u002Fdocs\u002Fentities\u002Fcatalog-skus)\n- [Filtering syntax](\u002Fdocs\u002Ffiltering)\n- [Limits and optimization](\u002Fdocs\u002Foptimization)\n","2026-10-23",{},1795415192052]