Skip to main content
POST
/
events
/
aggregate
JavaScript SDK
const aggregates = await client.events.aggregate.count({ filter: { assetIds: [1, 2, 3] } });
console.log('Number of events: ', aggregates[0].count)

const uniqueValues = await client.events.aggregate.uniqueValues({ filter: { assetIds: [1, 2, 3] }, fields: ['subtype'] });
console.log('Unique values: ', uniqueValues)
aggregate_type = client.events.aggregate(filter={"type": "failure"})
from cognite.client.data_classes.events import EventProperty
type_count = client.events.aggregate_cardinality_properties(EventProperty.metadata)
from cognite.client.data_classes.events import EventProperty
type_count = client.events.aggregate_cardinality_values(EventProperty.type)

from cognite.client.data_classes import filters
from cognite.client.data_classes.events import EventProperty
is_asset = filters.ContainsAny(EventProperty.asset_ids, 123)
plain_text_author_count = client.events.aggregate_cardinality_values(EventProperty.type, advanced_filter=is_asset)
count = client.events.aggregate_count()

from cognite.client.data_classes import filters
from cognite.client.data_classes.events import EventProperty
is_workorder = filters.Equals(EventProperty.type, "workorder")
workorder_count = client.events.aggregate_count(advanced_filter=is_workorder)
from cognite.client.data_classes.events import EventProperty
result = client.events.aggregate_unique_properties(EventProperty.metadata)
print(result.unique)
from cognite.client.data_classes.events import EventProperty
result = client.events.aggregate_unique_values(property=EventProperty.type)
print(result.unique)

from cognite.client.data_classes import filters
from cognite.client.data_classes.events import EventProperty
from cognite.client.utils import timestamp_to_ms
from datetime import datetime
is_after_2020 = filters.Range(EventProperty.start_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.events.aggregate_unique_values(EventProperty.type, advanced_filter=is_after_2020)
print(result.unique)

from cognite.client.data_classes.events import EventProperty
from cognite.client.data_classes import aggregations
agg = aggregations
not_planned = agg.Not(agg.Prefix("planned"))
is_after_2020 = filters.Range(EventProperty.start_time, gte=timestamp_to_ms(datetime(2020, 1, 1)))
result = client.events.aggregate_unique_values(EventProperty.type, advanced_filter=is_after_2020, aggregate_filter=not_planned)
print(result.unique)
Aggregate aggregateResult = 
client.events().aggregate(Request.create().withFilterParameter("source", "source"));
curl --request POST \
--url https://{cluster}.cognitedata.com/api/v1/projects/{project}/events/aggregate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"aggregate": "count",
"advancedFilter": {
"and": "<array>"
},
"filter": {
"startTime": {
"max": 1,
"min": 1
},
"endTime": {
"max": 1,
"min": 1
},
"activeAtTime": {
"max": 1,
"min": 1
},
"metadata": {},
"assetIds": [
4503599627370496
],
"assetExternalIds": [
"my.known.id"
],
"assetSubtreeIds": [
{
"id": 4503599627370496
}
],
"dataSetIds": [
{
"id": 4503599627370496
}
],
"source": "<string>",
"type": "<string>",
"subtype": "<string>",
"createdTime": {
"max": 1,
"min": 1
},
"lastUpdatedTime": {
"max": 1,
"min": 1
},
"externalIdPrefix": "my.known.prefix"
}
}
'
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://{cluster}.cognitedata.com/api/v1/projects/{project}/events/aggregate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'aggregate' => 'count',
'advancedFilter' => [
'and' => '<array>'
],
'filter' => [
'startTime' => [
'max' => 1,
'min' => 1
],
'endTime' => [
'max' => 1,
'min' => 1
],
'activeAtTime' => [
'max' => 1,
'min' => 1
],
'metadata' => [

],
'assetIds' => [
4503599627370496
],
'assetExternalIds' => [
'my.known.id'
],
'assetSubtreeIds' => [
[
'id' => 4503599627370496
]
],
'dataSetIds' => [
[
'id' => 4503599627370496
]
],
'source' => '<string>',
'type' => '<string>',
'subtype' => '<string>',
'createdTime' => [
'max' => 1,
'min' => 1
],
'lastUpdatedTime' => [
'max' => 1,
'min' => 1
],
'externalIdPrefix' => 'my.known.prefix'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://{cluster}.cognitedata.com/api/v1/projects/{project}/events/aggregate"

payload := strings.NewReader("{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"startTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"endTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"activeAtTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"metadata\": {},\n \"assetIds\": [\n 4503599627370496\n ],\n \"assetExternalIds\": [\n \"my.known.id\"\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"source\": \"<string>\",\n \"type\": \"<string>\",\n \"subtype\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"externalIdPrefix\": \"my.known.prefix\"\n }\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
require 'uri'
require 'net/http'

url = URI("https://{cluster}.cognitedata.com/api/v1/projects/{project}/events/aggregate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"aggregate\": \"count\",\n \"advancedFilter\": {\n \"and\": \"<array>\"\n },\n \"filter\": {\n \"startTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"endTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"activeAtTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"metadata\": {},\n \"assetIds\": [\n 4503599627370496\n ],\n \"assetExternalIds\": [\n \"my.known.id\"\n ],\n \"assetSubtreeIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"dataSetIds\": [\n {\n \"id\": 4503599627370496\n }\n ],\n \"source\": \"<string>\",\n \"type\": \"<string>\",\n \"subtype\": \"<string>\",\n \"createdTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"lastUpdatedTime\": {\n \"max\": 1,\n \"min\": 1\n },\n \"externalIdPrefix\": \"my.known.prefix\"\n }\n}"

response = http.request(request)
puts response.read_body
{
  "items": [
    {
      "count": 10
    }
  ]
}
{
"error": {
"code": 400,
"message": "`null` values aren't allowed."
}
}
{
"error": {
"code": 429,
"message": "Project exceeded maximum number='50' of concurrent requests. Please try again later."
}
}

Authorizations

Authorization
string
header
required

Access token issued by the CDF project's configured identity provider. Access token must be an OpenID Connect token, and the project must be configured to accept OpenID Connect tokens. Use a header key of 'Authorization' with a value of 'Bearer $accesstoken'. The token can be obtained through any flow supported by the identity provider.

Body

application/json

Request aggregate to count the number of Events matching the filters. Default aggregate for the endpoint.

aggregate
enum<string>

Type of aggregation to apply. count: Get an approximate number of Events matching the filters.

Available options:
count
advancedFilter
and · object

A query that matches items matching boolean combinations of other queries. It's built using one or more boolean clauses of the following types: and, or, or not

filter
object

Filter on events filter with exact match

Response

Response with a list of aggregation results.

Common aggregate structure to represent aggregate result which have one count for filter resultset (Documents Count, Property Cardinality, etc).

items
object[]
required
Required array length: 1 element
Last modified on July 13, 2026