Grouping and aggregates

Count and total records, and fetch several filtered groups in one request.

On this page

Aggregates#

GET/objects/{objectSlug}/records/aggregates

Calculates over every record that matches, not just one page.

ParameterMeaning
aggregatesA JSON array of up to 20 { "fieldId": "…", "operation": "…" }.
filters, search, deletedAs in List records.
groupByFieldIdOptional ID of a Select field. Results come back for each of its options.
Field typeOperations
Any except relationcount, count_empty, count_not_empty, count_unique, percent_empty, percent_not_empty
number, currencyalso sum, avg, min, max
date, date_timealso earliest, latest
checkboxalso count_true, count_false
relationcount only

Results are keyed by field ID, so ask for one operation per field in a request. If you repeat a field, only one result comes back.

cURL
curl --fail-with-body -G "$JEMERO_URL/objects/companies/records/aggregates" \
  -H "Authorization: Bearer $JEMERO_API_KEY" \
  --data-urlencode "aggregates=[{\"fieldId\":\"$REVENUE_FIELD_ID\",\"operation\":\"sum\"}]"
Node.js
const aggregates = [{ fieldId: process.env.REVENUE_FIELD_ID, operation: 'sum' }];
const url = new URL(`${process.env.JEMERO_URL}/objects/companies/records/aggregates`);
url.search = new URLSearchParams({ aggregates: JSON.stringify(aggregates) });

const response = await fetch(url, {
  headers: { Authorization: `Bearer ${process.env.JEMERO_API_KEY}` },
});
if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
console.log((await response.json()).values);
Python
import json
import os
import requests

aggregates = [{"fieldId": os.environ["REVENUE_FIELD_ID"], "operation": "sum"}]
response = requests.get(
    f"{os.environ['JEMERO_URL']}/objects/companies/records/aggregates",
    headers={"Authorization": f"Bearer {os.environ['JEMERO_API_KEY']}"},
    params={"aggregates": json.dumps(aggregates)},
    timeout=30,
)
response.raise_for_status()
print(response.json()["values"])
Response 200
{ "values": { "11a499d0-f2b7-493d-8bbd-bc709271e0e1": 125000000 } }

With groupByFieldId, the answer is keyed by option ID. Records with no option, or one that was removed, are under __none__. Empty groups are left out.

Grouped response 200
{
  "groups": {
    "dae82246-2e36-455a-8a9b-a406ca34f04e": {
      "11a499d0-f2b7-493d-8bbd-bc709271e0e1": 125000000
    }
  }
}

A calculation on a field that is hidden from your role is left out. A calculation that has no records to work on can be null.

Grouped lists#

GET/objects/{objectSlug}/records/groups

Returns the first page of several filtered groups in one request, such as the columns of a board.

ParameterMeaning
groupsRequired. A JSON array of 1–60 { "filters": [...] }.
filtersConditions applied to every group, as well as its own.
search, sorts, pageSizeAs in List records.
cURL
curl --fail-with-body -G "$JEMERO_URL/objects/companies/records/groups" \
  -H "Authorization: Bearer $JEMERO_API_KEY" \
  --data-urlencode "pageSize=5" \
  --data-urlencode "groups=[{\"filters\":[{\"fieldId\":\"$NAME_FIELD_ID\",\"operator\":\"contains\",\"value\":\"glob\"}]},{\"filters\":[{\"fieldId\":\"$NAME_FIELD_ID\",\"operator\":\"contains\",\"value\":\"labs\"}]}]"
Response 200
{
  "groups": [
    { "records": [], "total": 0, "totalIsCapped": false }
  ]
}

Groups come back in the order you sent them. Only the first page of each is returned. To read more of a group, use List records with the same filters. This endpoint covers live records only.

Errors#

StatusCause
400Invalid JSON, an unknown field, an operation the field type doesn't offer, or groupByFieldId isn't a Select field.
404 Object not foundNo object with that slug.