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

Aggregate calendar events

POST /v1/calendar-events/aggregate

Counts the events of one calendar over a period and sums their numeric fields, for example the total duration of an employee's meetings over a year. The calendar and the period are set inside the filter object.

Request fields (body)

Field Type Required Description
Fieldfilter Typeobject Requiredyes DescriptionThe calendar and the period to select. Accepts only type, ownerId, from, to, section. A field outside this set returns 400 UNSUPPORTED_FILTER
Fieldfilter.type Typestring Requiredyes DescriptionCalendar type: user, group, company_calendar
Fieldfilter.ownerId Typenumber Requiredyes DescriptionCalendar owner ID. For type=user — the employee ID from GET /v1/users, for type=group — the workgroup ID
Fieldfilter.from Typestring Requiredno DescriptionStart of the event selection period (ISO 8601). Without from and to, the same period applies as for the event list: from one month back to three months ahead
Fieldfilter.to Typestring Requiredno DescriptionEnd of the event selection period (ISO 8601)
Fieldfilter.section Typenumber Requiredno DescriptionCalendar section ID — the value of the event's sectionId field. Accepted as a single number. An array returns 400 UNSUPPORTED_FILTER
Fieldaggregate Typearray Requiredno DescriptionArray of { "field": "<field>", "function": "<function>" } expressions, up to 5. Functions: count, sum, avg, min, max. count accepts only "field": "*". Numeric functions accept fields of type number: of these, durationSeconds contains the duration; the rest are identifiers (id, ownerId, sectionId, createdBy and others). Without the parameter, only count is returned

Examples

curl — personal key

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/calendar-events/aggregate" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": {
      "type": "user",
      "ownerId": 1,
      "from": "2026-01-01",
      "to": "2026-12-31"
    },
    "aggregate": [
      { "field": "durationSeconds", "function": "sum" }
    ]
  }'

curl — OAuth application

Terminal
curl -X POST "https://vibecode.bitrix24.com/v1/calendar-events/aggregate" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "filter": {
      "type": "user",
      "ownerId": 1,
      "from": "2026-01-01",
      "to": "2026-12-31"
    },
    "aggregate": [
      { "field": "durationSeconds", "function": "sum" }
    ]
  }'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/calendar-events/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: {
      type: 'user',
      ownerId: 1,
      from: '2026-01-01',
      to: '2026-12-31',
    },
    aggregate: [
      { field: 'durationSeconds', function: 'sum' },
    ],
  }),
})

const { success, data } = await res.json()
console.log('Events:', data.count, 'hours:', data.aggregates.durationSeconds.sum / 3600)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/calendar-events/aggregate', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    filter: {
      type: 'user',
      ownerId: 1,
      from: '2026-01-01',
      to: '2026-12-31',
    },
    aggregate: [
      { field: 'durationSeconds', function: 'sum' },
    ],
  }),
})

const { success, data } = await res.json()

Other scenarios

The blocks below are request bodies.

Number of events in an employee's calendar over the default period, without loading the records:

JSON
{ "filter": { "type": "user", "ownerId": 1 } }

Number of events in one calendar section over a year:

JSON
{ "filter": { "type": "user", "ownerId": 1, "from": "2026-01-01", "to": "2026-12-31", "section": 3 } }

Response fields

Field Type Description
Fieldsuccess Typeboolean DescriptionAlways true on success
Fielddata.count Typenumber DescriptionNumber of calendar events over the period
Fielddata.aggregates Typeobject DescriptionResults of the numeric functions: the key is the field name, inside is the value for each function, for example durationSeconds.sum. An empty object if the aggregate array is not passed
Fielddata.meta.totalRecords Typenumber DescriptionTotal number of records matching the filter
Fielddata.meta.recordsProcessed Typenumber DescriptionNumber of records read. 0 when only count is computed
Fielddata.meta.truncated Typeboolean Descriptiontrue if the numbers are not computed over all records matching the filter: fewer records were read than data.count promised — including when more than 5000 matched the filter — or the slice was cut off by a subpage error. The size of the shortfall is reported in data.meta.recordsShortfall, the cut-off slice in data.meta.pageErrorSample. Always present, false on a complete response. If the request has no numeric functions, no records are loaded and the flag is always false

Response example

Sum of event durations over a year:

JSON
{
  "success": true,
  "data": {
    "count": 6,
    "aggregates": {
      "durationSeconds": { "sum": 104400 }
    },
    "meta": {
      "totalRecords": 6,
      "recordsProcessed": 6,
      "truncated": false
    }
  }
}

Error response example

400 — the required type and ownerId are not passed in filter:

JSON
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_PARAMS",
    "message": "POST /v1/calendar-events/aggregate requires filter params: type, ownerId. Example body: { \"filter\": {\"type\":\"...\",\"ownerId\":\"...\"} }"
  }
}

Errors

HTTP Code Description
HTTP400 CodeMISSING_REQUIRED_PARAMS Descriptionfilter lacks type and/or ownerId, or the value is empty or passed as an array or an object. These fields at the top level of the body, outside filter, do not count. message lists the missing fields
HTTP400 CodeUNSUPPORTED_FILTER Descriptionfilter contains a field outside the type, ownerId, from, to, section set, or section is passed as an array
HTTP400 CodeINVALID_PARAMS DescriptionUnknown aggregation function. The message lists the allowed ones
HTTP400 CodeINVALID_PARAMS DescriptionEmpty aggregate array
HTTP400 CodeINVALID_PARAMS DescriptionMore than 5 expressions in aggregate
HTTP400 CodeINVALID_PARAMS Descriptioncount with a field other than "*"
HTTP400 CodeINVALID_PARAMS DescriptionNumeric function on a field whose type is not number. The message names the field type
HTTP400 CodeINVALID_PARAMS DescriptionNumeric function on a field that events do not have. The message lists the available numeric fields
HTTP400 CodeINVALID_PARAMS DescriptionNumeric function without a field or with the "*" field
HTTP400 CodeINVALID_PARAMS DescriptiongroupBy is passed — calendar events have no fields to group by
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the calendar scope
HTTP401 CodeTOKEN_MISSING DescriptionThe API key has no configured tokens
HTTP429 CodeRATE_LIMITED DescriptionRequest limit exceeded: 300 per minute per Bitrix24 account. All API keys of the account 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

The count matches the list. Without from, to, and section, data.count equals meta.total of the event list for the same type and ownerId: both count over the same default period. There is no grouping, so a count across several sections or employees takes a separate request per section or per calendar owner.

A nonexistent calendar returns zero, not an error. An unknown type value or a nonexistent ownerId returns 200 with count: 0. A zero count does not tell an empty calendar from a mistake in the type + ownerId pair — check the pair with an event list request.

Numeric functions are computed over the records read. count without numeric functions is returned without loading the records. sum, avg, min, max read events page by page, at most 5000. When the response comes with meta.truncated: true, a truncated: true marker sits inside each field's object in data.aggregates, and a warning with the AGGREGATE_TRUNCATED code is added to data.meta.warnings. Full details — Aggregation POST — the 5000-record ceiling.

See also