Skip to main content
POST
/
v2
/
entities
/
aggregate
Aggregate Entities
curl --request POST \
  --url https://public.api.serval.com/v2/entities/aggregate \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "teamId": "<string>",
  "entitySchemaId": "<string>",
  "entityTypeIds": [
    "<string>"
  ],
  "createdAfter": "2023-11-07T05:31:56Z",
  "createdBefore": "2023-11-07T05:31:56Z",
  "fieldKey": "<string>",
  "sumFieldKey": "<string>"
}
'
import requests

url = "https://public.api.serval.com/v2/entities/aggregate"

payload = {
"teamId": "<string>",
"entitySchemaId": "<string>",
"entityTypeIds": ["<string>"],
"createdAfter": "2023-11-07T05:31:56Z",
"createdBefore": "2023-11-07T05:31:56Z",
"fieldKey": "<string>",
"sumFieldKey": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
teamId: '<string>',
entitySchemaId: '<string>',
entityTypeIds: ['<string>'],
createdAfter: '2023-11-07T05:31:56Z',
createdBefore: '2023-11-07T05:31:56Z',
fieldKey: '<string>',
sumFieldKey: '<string>'
})
};

fetch('https://public.api.serval.com/v2/entities/aggregate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://public.api.serval.com/v2/entities/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([
'teamId' => '<string>',
'entitySchemaId' => '<string>',
'entityTypeIds' => [
'<string>'
],
'createdAfter' => '2023-11-07T05:31:56Z',
'createdBefore' => '2023-11-07T05:31:56Z',
'fieldKey' => '<string>',
'sumFieldKey' => '<string>'
]),
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://public.api.serval.com/v2/entities/aggregate"

payload := strings.NewReader("{\n \"teamId\": \"<string>\",\n \"entitySchemaId\": \"<string>\",\n \"entityTypeIds\": [\n \"<string>\"\n ],\n \"createdAfter\": \"2023-11-07T05:31:56Z\",\n \"createdBefore\": \"2023-11-07T05:31:56Z\",\n \"fieldKey\": \"<string>\",\n \"sumFieldKey\": \"<string>\"\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))

}
HttpResponse<String> response = Unirest.post("https://public.api.serval.com/v2/entities/aggregate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"teamId\": \"<string>\",\n \"entitySchemaId\": \"<string>\",\n \"entityTypeIds\": [\n \"<string>\"\n ],\n \"createdAfter\": \"2023-11-07T05:31:56Z\",\n \"createdBefore\": \"2023-11-07T05:31:56Z\",\n \"fieldKey\": \"<string>\",\n \"sumFieldKey\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://public.api.serval.com/v2/entities/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 \"teamId\": \"<string>\",\n \"entitySchemaId\": \"<string>\",\n \"entityTypeIds\": [\n \"<string>\"\n ],\n \"createdAfter\": \"2023-11-07T05:31:56Z\",\n \"createdBefore\": \"2023-11-07T05:31:56Z\",\n \"fieldKey\": \"<string>\",\n \"sumFieldKey\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "buckets": [
    {
      "createdAtBucketStart": "2023-11-07T05:31:56Z",
      "count": 123,
      "sum": 123
    }
  ]
}
{
"message": "<string>",
"detail": {
"type": "<string>",
"value": "<string>",
"debug": {}
}
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
teamId
string

The ID of the team.

entitySchemaId
string

The entity schema ("database") to aggregate over. Required — an unscoped aggregate would scan every visible schema's entities, which is timeout-class on large tenants. The schema must be visible to team_id (the team's own, or shared org-wide).

groupBy
enum<string>

The dimension to group counts by.

Available options:
ENTITY_AGGREGATION_DIMENSION_UNSPECIFIED,
ENTITY_AGGREGATION_DIMENSION_ENTITY_TYPE,
ENTITY_AGGREGATION_DIMENSION_CREATED_AT,
ENTITY_AGGREGATION_DIMENSION_FIELD_VALUE
granularity
enum<string> | null

Bucket size for the CREATED_AT dimension. Required when group_by is CREATED_AT; ignored for ENTITY_TYPE.

Available options:
ENTITY_AGGREGATION_TIME_GRANULARITY_UNSPECIFIED,
ENTITY_AGGREGATION_TIME_GRANULARITY_DAY,
ENTITY_AGGREGATION_TIME_GRANULARITY_MONTH
entityTypeIds
string[]

Optional restriction to specific entity types within the schema. IDs outside the schema's live types are dropped, never counted. Also the chunking lever for callers that want to bound per-request work on very large schemas.

createdAfter
string<date-time> | null

Optional: only count entities created at or after this time.

createdBefore
string<date-time> | null

Optional: only count entities created before this time (exclusive).

fieldKey
string | null

The field to group by, by key on the target entity type. Required for the FIELD_VALUE dimension (which also requires exactly one entity_type_ids entry); ignored otherwise.

sumFieldKey
string | null

Optional, FIELD_VALUE dimension only: a NUMBER field (by key, on the same single entity type) whose values are summed per bucket — e.g. group hardware assets by state and sum cost for spend-by-state. When set, every bucket carries sum alongside count; entities with no value for the summed field contribute nothing to sums.

Response

Success

buckets
(Created At Bucket Start · object | Entity Type · object | Field Value · object)[]

ENTITY_TYPE buckets are sorted by count descending (name ascending on ties); CREATED_AT buckets are sorted by bucket start ascending; FIELD_VALUE buckets follow the field's option display order (BOOL: Yes then No), with the empty-value bucket last.

Set for the CREATED_AT dimension: inclusive start of the time bucket, in UTC.