[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Forder-properties\u002Faggregate":3,"docs-tabs-entities\u002Forder-properties\u002Faggregate":6},{"content":4,"lastmod":5},"## Aggregate order properties\n\n`POST \u002Fv1\u002Forder-properties\u002Faggregate`\n\nCounts order 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| `personTypeId` | Payer type ID from [`GET \u002Fv1\u002Fperson-types`](\u002Fdocs\u002Fentities\u002Fperson-types\u002Flist). For `groupBy` |\n| `type` | Property type — for `groupBy` |\n| `required` | Whether the field is required when placing an order — for `groupBy` |\n| `active` | Active flag — for `groupBy` |\n| `sort` | Sort order — for `sum`, `avg`, `min`, `max` |\n| `inputFieldLocation` | Deprecated field. Bitrix24 does not use it — a numeric field |\n| `id` | Property ID from [list order properties](.\u002Flist.md). A numeric field |\n| `propsGroupId` | Group ID from a property with the same payer type in [list order properties](.\u002Flist.md). A numeric field |\n\nFields for `groupBy` are listed in `data.aggregatable` of [`GET \u002Fv1\u002Forder-properties\u002Ffields`](.\u002Ffields.md). Numeric functions accept fields of type `number` from the same schema: `id`, `personTypeId`, `propsGroupId`, `sort`, `inputFieldLocation`.\n\n## Request body fields\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `aggregate` | array | no | An array of expressions such as `{ \"field\": \"sort\", \"function\": \"sum\" }`, with 1 to 5 expressions. 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\u002Forder-properties\u002Ffields`](.\u002Ffields.md).\u003Cbr>[Filtering syntax](\u002Fdocs\u002Ffiltering). Example: `{ \"id\": 125 }` |\n| `groupBy` | string \\| string[] | no | A grouping field or an array of up to 5 fields. Allowed fields: `personTypeId`, `type`, `required`, `active` |\n| `groupOrderBy` | array | no | Sort groups: `[{ \"field\": \"count\", \"direction\": \"desc\" }]`. `field` accepts `count`, a field from `groupBy`, or `\u003Cfield>:\u003Cfunction>` from `aggregate`. Directions: `asc`, `desc`. If `direction` is omitted, defaults to `desc`. Requires `groupBy` |\n| `groupLimit` | number | no | Number of returned groups: an integer from 1 to 1000. When omitted, groups are not limited. Requires `groupBy` |\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Forder-properties\u002Faggregate\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"filter\": { \"id\": 125 },\n    \"aggregate\": [\n      { \"field\": \"*\", \"function\": \"count\" },\n      { \"field\": \"sort\", \"function\": \"sum\" }\n    ],\n    \"groupBy\": [\"type\", \"active\"],\n    \"groupOrderBy\": [{ \"field\": \"count\", \"direction\": \"desc\" }],\n    \"groupLimit\": 10\n  }'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Forder-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 '{\n    \"filter\": { \"id\": 125 },\n    \"aggregate\": [\n      { \"field\": \"*\", \"function\": \"count\" },\n      { \"field\": \"sort\", \"function\": \"sum\" }\n    ],\n    \"groupBy\": [\"type\", \"active\"],\n    \"groupOrderBy\": [{ \"field\": \"count\", \"direction\": \"desc\" }],\n    \"groupLimit\": 10\n  }'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Forder-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    filter: { id: 125 },\n    aggregate: [\n      { field: '*', function: 'count' },\n      { field: 'sort', function: 'sum' },\n    ],\n    groupBy: ['type', 'active'],\n    groupOrderBy: [{ field: 'count', direction: 'desc' }],\n    groupLimit: 10,\n  }),\n})\n\nconst { data } = await res.json()\nconsole.log('Properties by type and active status:', data.groups)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Forder-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    filter: { id: 125 },\n    aggregate: [\n      { field: '*', function: 'count' },\n      { field: 'sort', function: 'sum' },\n    ],\n    groupBy: ['type', 'active'],\n    groupOrderBy: [{ field: 'count', direction: 'desc' }],\n    groupLimit: 10,\n  }),\n})\n\nconst { data } = await res.json()\n```\n\n## Other scenarios\n\nThe blocks below are request bodies.\n\nCount properties matching the filter without grouping or numeric functions — records are not downloaded:\n\n```json\n{ \"filter\": { \"id\": 125 } }\n```\n\nSum the sort order with grouping when the filter matches no records:\n\n```json\n{\n  \"filter\": { \"id\": 125, \"code\": \"ABSENT_DELIVERY_COMMENT\" },\n  \"aggregate\": [{ \"field\": \"sort\", \"function\": \"sum\" }],\n  \"groupBy\": [\"type\", \"active\"]\n}\n```\n\nFor the last request, `data.count` and the sum are `0`, and `data.groups` is an empty array.\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, such as `{ \"sort\": { \"sum\": 500 } }`. 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 grouping field values, `count`, and `aggregates`. `personTypeId` is a `number`, `type` is a `string`, and `required` and `active` are `boolean` |\n| `data.groups[].count` | number | Number of processed records in the group |\n| `data.groups[].aggregates` | object | Numeric results within the group, in the same format as `data.aggregates` |\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\": 1,\n    \"aggregates\": {\n      \"sort\": {\n        \"sum\": 500\n      }\n    },\n    \"groups\": [\n      {\n        \"type\": \"STRING\",\n        \"active\": false,\n        \"count\": 1,\n        \"aggregates\": {\n          \"sort\": {\n            \"sum\": 500\n          }\n        }\n      }\n    ],\n    \"meta\": {\n      \"totalRecords\": 1,\n      \"recordsProcessed\": 1,\n      \"truncated\": false,\n      \"groupTotal\": 1,\n      \"groupsTruncated\": false\n    }\n  }\n}\n```\n\n## Error response example\n\n400 — the string field `name` was passed to the numeric function `sum`:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"Field 'name' is not numeric (type: string). Only number fields support sum.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `aggregate` is not an array or is empty |\n| 400 | `INVALID_PARAMS` | `aggregate` contains more than 5 expressions |\n| 400 | `INVALID_PARAMS` | The function is unknown or missing |\n| 400 | `INVALID_PARAMS` | The field for `count` is not `\"*\"` |\n| 400 | `INVALID_PARAMS` | The field for `sum`, `avg`, `min`, or `max` is missing or is `\"*\"` |\n| 400 | `INVALID_PARAMS` | A nonnumeric field such as `name` or `defaultValue` was passed to a numeric function |\n| 400 | `INVALID_PARAMS` | The numeric function field was not found. The message lists allowed fields: `id`, `personTypeId`, `propsGroupId`, `sort`, `inputFieldLocation` |\n| 400 | `INVALID_PARAMS` | `op`, `field`, or `function` was passed at the top level without the `aggregate` array |\n| 400 | `INVALID_PARAMS` | `groupBy` is not a string or an array of strings, or the array contains a value of another type |\n| 400 | `INVALID_PARAMS` | The grouping field is not one of `personTypeId`, `type`, `required`, `active` |\n| 400 | `INVALID_PARAMS` | `groupBy` has more than 5 fields |\n| 400 | `INVALID_PARAMS` | `groupBy` contains a reserved name: `count`, `aggregates`, `meta`, `groups` |\n| 400 | `INVALID_PARAMS` | `groupOrderBy` was passed without `groupBy` |\n| 400 | `INVALID_PARAMS` | `groupLimit` was passed without `groupBy` |\n| 400 | `INVALID_PARAMS` | `groupOrderBy` is not an array |\n| 400 | `INVALID_PARAMS` | A `groupOrderBy` item is not an object with a nonempty string `field` |\n| 400 | `INVALID_PARAMS` | `groupOrderBy.direction` is neither `asc` nor `desc` |\n| 400 | `INVALID_PARAMS` | The `\u003Cfield>:\u003Cfunction>` key in `groupOrderBy.field` is absent from the numeric `aggregate` expressions |\n| 400 | `INVALID_PARAMS` | `groupOrderBy.field` is not `count`, a field from `groupBy`, or a numeric `aggregate` expression key |\n| 400 | `INVALID_PARAMS` | `groupLimit` is not an integer from 1 to 1000 |\n| 400 | `UNKNOWN_FILTER_FIELD` | Unknown field in `filter` |\n| 400 | `INVALID_FILTER_FIELD` | A field name in `filter` starts with the unsupported prefix `@` or `!@` |\n| 400 | `INVALID_FILTER_OPERATOR` | Unsupported operator, an empty condition object, or `$or` \u002F `$and` logical conditions |\n| 400 | `INVALID_FILTER_SHAPE` | `filter` is not an object of conditions, for example a string, number, or array |\n| 400 | `INVALID_DUPLICATE_FILTER_FIELD` | Two filter conditions resolve to the same condition, for example `$ne` and `$nin` for one field |\n| 422 | `AGGREGATION_LIMIT_EXCEEDED` | When the cap is enforced for the portal, more than 5000 records match the filter and the request requires numeric calculations or grouping. Records are not downloaded. Narrow the filter |\n| 422 | `BITRIX_ERROR` | The key's user does not have permission in Bitrix24. The Bitrix24 code is in `error.b24Code`: `200040300010` |\n| 403 | `BITRIX_ACCESS_DENIED` | The portal credentials do not have the `sale` scope (`insufficient_scope`) |\n| 422 | `BITRIX_ERROR` | A business error with the Bitrix24 message |\n| 503 | `BITRIX_TIMEOUT` | Bitrix24 did not respond in time. Retry after the interval in `Retry-After` |\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 tokens are configured for the API key |\n| 429 | `RATE_LIMITED` | The request rate limit was exceeded. The effective limit is in the `x-ratelimit-limit` header. 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## See also\n\n- [List order properties](.\u002Flist.md)\n- [Search order properties](.\u002Fsearch.md)\n- [Order property fields](.\u002Ffields.md)\n- [Order properties](\u002Fdocs\u002Fentities\u002Forder-properties)\n- [Filtering syntax](\u002Fdocs\u002Ffiltering)\n- [Limits and optimization](\u002Fdocs\u002Foptimization)\n- [Aggregation POST — the 5000-record ceiling](\u002Fdocs\u002Fentity-api#aggregation-post-the-5000-record-ceiling)\n","2026-10-09",{},1795415262269]