[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fdeal-categories\u002Faggregate":3,"docs-tabs-entities\u002Fdeal-categories\u002Faggregate":6},{"content":4,"lastmod":5},"\n## Aggregate funnels\n\n`POST \u002Fv1\u002Fdeal-categories\u002Faggregate`\n\nCounts funnels matching a filter and computes numeric aggregates over them. Without a request body it returns the total number of funnels in a single call, without fetching records.\n\n## Request fields (body)\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `aggregate` | array | no | Array of aggregations. Each element: `{ \"field\": \"sort\", \"function\": \"sum\" }`. Functions: `count`, `sum`, `avg`, `min`, `max`. For `count`, the field is `\"*\"`. Without the array only `count` is returned |\n| `filter` | object | no | Exact match and `$in` on `id`, `name`, `sort`. Filtering by `isLocked` or `createdAt` returns `400 UNSUPPORTED_FILTER`. [Filtering syntax](\u002Fdocs\u002Ffiltering) |\n| `groupBy` | string or string[] | no | A user-defined field name or an array of up to 5 user-defined field names returned by the fields endpoint. The schema has no standard grouping fields |\n\nNumeric functions (`sum`\u002F`avg`\u002F`min`\u002F`max`) apply to numeric funnel fields — `sort`. The schema declares no standard fields for grouping. `groupBy` accepts user-defined fields returned by the fields endpoint; other fields return `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdeal-categories\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdeal-categories\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```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdeal-categories\u002Faggregate', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({}),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Total funnels:', data.count)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdeal-categories\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})\n\nconst { success, data } = await res.json()\n```\n\n## Other scenarios\n\nTo count records, use `count` with the field set to `\"*\"`. This is the fastest request because it does not fetch records. Without the `aggregate` array the result is the same:\n\n```json\n{ \"aggregate\": [{ \"field\": \"*\", \"function\": \"count\" }] }\n```\n\nSum of the `sort` field across all funnels:\n\n```json\n{\n  \"aggregate\": [{ \"field\": \"sort\", \"function\": \"sum\" }]\n}\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data` | object | Aggregation result: record count, function values and selection details |\n| `data.count` | number | Total number of funnels matching the filter |\n| `data.aggregates` | object | Results of numeric aggregations by field, in the form `{ \"sort\": { \"sum\": 2410 } }`. Empty object if the `aggregate` array is not passed |\n| `data.meta.totalRecords` | number | Total number of funnels matching the filter |\n| `data.meta.recordsProcessed` | number | How many records were processed: `0` for a plain `count`, the number of records for numeric functions |\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.recordsShortfall` | number | How many funnels matching the filter were left out of the calculation: `totalRecords` minus `recordsProcessed`. Present only when fewer records were read than `data.count` promised |\n| `data.meta.pageErrorSample` | object | The sub-page error that cut the slice short: `code` and `message`. Present only when the slice was cut short |\n| `data.meta.warnings` | array | An array with a single warning: `code` is `AGGREGATE_TRUNCATED`, `message` is the text. Present only together with `data.meta.truncated: true` |\n\n## Response example\n\nCount request (body `{}`):\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"count\": 6,\n    \"aggregates\": {},\n    \"meta\": {\n      \"totalRecords\": 6,\n      \"recordsProcessed\": 0,\n      \"truncated\": false\n    }\n  }\n}\n```\n\nSum of the `sort` field (body `{ \"aggregate\": [{ \"field\": \"sort\", \"function\": \"sum\" }] }`):\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"count\": 6,\n    \"aggregates\": { \"sort\": { \"sum\": 2410 } },\n    \"meta\": {\n      \"totalRecords\": 6,\n      \"recordsProcessed\": 6,\n      \"truncated\": false\n    }\n  }\n}\n```\n\n## Error response example\n\n400 — `groupBy` was passed when no user-defined grouping fields were available:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"groupBy is not supported on this entity\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | Unsupported `groupBy` field or a numeric function on a non-numeric field |\n| 403 | `SCOPE_DENIED` | The API key lacks the `crm` scope |\n| 401 | `TOKEN_MISSING` | The API key has no configured tokens |\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**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 `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 funnels](\u002Fdocs\u002Fentities\u002Fdeal-categories\u002Flist)\n- [Search funnels](\u002Fdocs\u002Fentities\u002Fdeal-categories\u002Fsearch)\n- [Filtering syntax](\u002Fdocs\u002Ffiltering)\n","2026-10-29",{},1794739365700]