[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fbasket-item-properties\u002Faggregate":3,"docs-tabs-entities\u002Fbasket-item-properties\u002Faggregate":6},{"content":4,"lastmod":5},"## Aggregate basket item properties\n\n`POST \u002Fv1\u002Fbasket-item-properties\u002Faggregate`\n\nCounts basket item properties by filter and grouping fields, and calculates the sum, average, minimum, and maximum of numeric fields.\n\n## Standard fields\n\n| Field | Purpose |\n|---|---|\n| `basketId` | Basket item ID. Source: [`GET \u002Fv1\u002Fbasket-items`](\u002Fdocs\u002Fentities\u002Fbasket-items\u002Flist). For `groupBy` and numeric functions |\n| `code` | Property symbolic code — for `groupBy` |\n| `sort` | Sort order — for `sum`, `avg`, `min`, `max` |\n| `id` | Property ID. Source: [`GET \u002Fv1\u002Fbasket-item-properties`](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Flist). A numeric field |\n\nFields for `groupBy` are listed in `data.aggregatable` of [`GET \u002Fv1\u002Fbasket-item-properties\u002Ffields`](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Ffields). Numeric functions accept fields of type `number`: `id`, `basketId`, `sort`.\n\n## Request body fields\n\n| Field | Type | Required | Description |\n|---|---|---|---|\n| `aggregate` | array | no | An array of expressions with `field` and `function`. Functions: `count`, `sum`, `avg`, `min`, `max`. For `count`, the field is `\"*\"`. When omitted, defaults to `[{ \"field\": \"*\", \"function\": \"count\" }]` |\n| `filter` | object | no | Filter by fields from [`GET \u002Fv1\u002Fbasket-item-properties\u002Ffields`](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Ffields).\u003Cbr>[Filtering syntax](\u002Fdocs\u002Ffiltering). Example: `{ \"basketId\": 1001 }` |\n| `groupBy` | string \\| string[] | no | A grouping field or array of fields: `basketId`, `code` |\n| `groupOrderBy` | array | no | Sort groups using objects with `field` and `direction`. Use `count`, a field from `groupBy`, or `\u003Cfield>:\u003Cfunction>` from a numeric `aggregate` expression. Directions: `asc`, `desc`. Defaults to `desc`. Requires `groupBy` |\n| `groupLimit` | number | no | Number of groups to return. Requires `groupBy` |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fbasket-item-properties\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"aggregate\":[{\"field\":\"*\",\"function\":\"count\"}],\"groupBy\":\"code\",\"groupOrderBy\":[{\"field\":\"count\",\"direction\":\"desc\"}],\"groupLimit\":3}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fbasket-item-properties\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"aggregate\":[{\"field\":\"*\",\"function\":\"count\"}],\"groupBy\":\"code\",\"groupOrderBy\":[{\"field\":\"count\",\"direction\":\"desc\"}],\"groupLimit\":3}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fbasket-item-properties\u002Faggregate', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    \"aggregate\": [\n      {\n        \"field\": \"*\",\n        \"function\": \"count\"\n      }\n    ],\n    \"groupBy\": \"code\",\n    \"groupOrderBy\": [\n      {\n        \"field\": \"count\",\n        \"direction\": \"desc\"\n      }\n    ],\n    \"groupLimit\": 3\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fbasket-item-properties\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    \"aggregate\": [\n      {\n        \"field\": \"*\",\n        \"function\": \"count\"\n      }\n    ],\n    \"groupBy\": \"code\",\n    \"groupOrderBy\": [\n      {\n        \"field\": \"count\",\n        \"direction\": \"desc\"\n      }\n    ],\n    \"groupLimit\": 3\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\nTo group by multiple fields, pass `groupBy` as an array.\n\n## Other scenarios\n\nThe blocks below are request bodies.\n\nCount properties of one basket item:\n\n```json\n{\n  \"filter\": {\n    \"basketId\": 1001\n  },\n  \"aggregate\": [\n    {\n      \"field\": \"*\",\n      \"function\": \"count\"\n    }\n  ]\n}\n```\n\nSum the sort order and find the maximum property ID:\n\n```json\n{\n  \"aggregate\": [\n    {\n      \"field\": \"sort\",\n      \"function\": \"sum\"\n    },\n    {\n      \"field\": \"id\",\n      \"function\": \"max\"\n    }\n  ]\n}\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 properties matching the filter |\n| `data.aggregates` | object | Numeric results by field and function. Empty for `count` alone |\n| `data.aggregates.\u003Cfield>.truncated` | boolean | Present as `true` when numeric results were calculated from an incomplete set of records |\n| `data.groups` | array | Present with `groupBy`. Each group contains the grouping field value, `count`, and `aggregates` |\n| `data.groups[].count` | number | Number of processed records in the group |\n| `data.groups[].aggregates` | object | Numeric results within the group |\n| `data.groups[].truncated` | boolean | Present as `true` for an incomplete set of records. The group's count and calculations cover the processed records |\n| `data.meta.totalRecords` | number | Total number of records matching the filter |\n| `data.meta.recordsProcessed` | number | Number of processed records, up to 5000. `0` without grouping or numeric functions |\n| `data.meta.truncated` | boolean | `true` when fewer records were read than the reported total, including due to the 5000-record cap, or when reading stopped on a subpage error. `false` for a complete response. Always `false` without grouping or numeric functions |\n| `data.meta.recordsShortfall` | number | Number of unread records: `totalRecords - recordsProcessed`. Present when records are missing, including at the 5000-record cap |\n| `data.meta.pageErrorSample` | object | A sample subpage error. Present when reading stopped on an error |\n| `data.meta.warnings` | array | Contains a warning with code `AGGREGATE_TRUNCATED` for an incomplete set of records |\n| `data.meta.groupTotal` | number | Present with `groupBy`: the number of groups before `groupLimit` is applied |\n| `data.meta.groupsTruncated` | boolean | Present with `groupBy`. `true` when `groupLimit` limits the returned groups |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"count\": 249,\n    \"aggregates\": {},\n    \"groups\": [\n      {\n        \"code\": \"CATALOG.XML_ID\",\n        \"count\": 69,\n        \"aggregates\": {}\n      },\n      {\n        \"code\": \"PRODUCT.XML_ID\",\n        \"count\": 69,\n        \"aggregates\": {}\n      },\n      {\n        \"code\": \"Color\",\n        \"count\": 39,\n        \"aggregates\": {}\n      }\n    ],\n    \"meta\": {\n      \"totalRecords\": 249,\n      \"recordsProcessed\": 249,\n      \"truncated\": false,\n      \"groupTotal\": 7,\n      \"groupsTruncated\": true\n    }\n  }\n}\n```\n\nWithout `groupBy`, the response omits `data.groups`.\n\n## Error response example\n\n400 — the field `name` is not available for grouping:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"groupBy field 'name' is not aggregatable on this entity. Available: basketId, code.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|---|---|---|\n| 400 | `INVALID_PARAMS` | Unknown aggregate function |\n| 400 | `INVALID_PARAMS` | The `groupBy` field is neither `basketId` nor `code` |\n| 400 | `INVALID_PARAMS` | A numeric function was requested for a string field such as `value` |\n| 422 | `BITRIX_ERROR` | Bitrix24 rejected the request. The reason is in `error.message` |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 could not be reached |\n| 403 | `SCOPE_DENIED` | The API key lacks the `sale` scope |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |\n| 401 | `TOKEN_MISSING` | No Bitrix24 access tokens are configured |\n| 429 | `RATE_LIMITED` | The request rate limit was exceeded. Retry after the interval in the `Retry-After` header |\n\nFor the full list of common API errors, see [Error codes](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**Counting and calculations.** A lone `count` without `groupBy` does not download records. Numeric functions and grouping require reading records.\n\n## See also\n\n- [List basket item properties](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Flist)\n- [Search basket item properties](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Fsearch)\n- [Basket item property fields](\u002Fdocs\u002Fentities\u002Fbasket-item-properties\u002Ffields)\n- [Filtering syntax](\u002Fdocs\u002Ffiltering)\n- [Limits and optimization](\u002Fdocs\u002Foptimization)\n","2026-10-12",{},1795415168380]