KasarKasar Docs
API Reference

Aggregations

Run SQL-native aggregation queries on any object -- count, sum, average, min, max, and group by.

The Aggregate endpoint lets you compute metrics directly on your CRM data without fetching individual records. It supports standard SQL aggregation functions with optional grouping.

Aggregate records

GET /api/v1/aggregate/{object}

Path parameters

ParameterTypeDescription
objectstringThe object to aggregate (e.g., opportunities, contacts)

Query parameters

ParameterTypeRequiredDescription
fieldstringYesThe field to aggregate (e.g., amount, id, status)
functionstringYesAggregation function: COUNT, SUM, AVG, MIN, MAX, COUNT_DISTINCT
group_bystringNoField to group results by
filter_fieldstringNoField to filter on before aggregating
filter_operatorstringNoFilter operator (e.g., equals, gt, lt, contains, is_null)
filter_valuestringNoValue for the filter

Validation rules

  • The field must exist on the target object.
  • SUM and AVG are restricted to numeric field types: NUMBER, CURRENCY, PERCENTAGE, FLOAT, and INTEGER. Using them on non-numeric fields returns a validation error.
  • COUNT, COUNT_DISTINCT, MIN, and MAX work on any field type.
  • When filter_field is provided, filter_operator and filter_value are also required.

Scalar response

When no group_by is specified, a single aggregated value is returned.

{
  "object_name": "opportunities",
  "field": "amount",
  "function": "SUM",
  "value": 284500.00
}

Grouped response

When group_by is specified, results are broken down by each distinct value of the grouping field.

{
  "object_name": "opportunities",
  "field": "amount",
  "function": "SUM",
  "group_by": "status",
  "results": [
    { "group": "open", "value": 150000.00 },
    { "group": "negotiation", "value": 85000.00 },
    { "group": "closed_won", "value": 49500.00 }
  ]
}

Errors

StatusCodeDescription
400INVALID_OBJECTThe object name does not exist
400VALIDATION_ERRORThe field does not exist, or the function is incompatible with the field type

Examples

Count all contacts:

curl -X GET "https://kasar.app/api/v1/aggregate/contacts?field=id&function=COUNT" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Sum opportunity amounts:

curl -X GET "https://kasar.app/api/v1/aggregate/opportunities?field=amount&function=SUM" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Average deal size grouped by status:

curl -X GET "https://kasar.app/api/v1/aggregate/opportunities?field=amount&function=AVG&group_by=status" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Count distinct companies per country:

curl -X GET "https://kasar.app/api/v1/aggregate/companies?field=name&function=COUNT_DISTINCT&group_by=country" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Sum revenue with a filter:

curl -X GET "https://kasar.app/api/v1/aggregate/opportunities?field=amount&function=SUM&filter_field=status&filter_operator=equals&filter_value=closed_won" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

Max deal value:

curl -X GET "https://kasar.app/api/v1/aggregate/opportunities?field=amount&function=MAX" \
  -H "Authorization: Bearer YOUR_API_TOKEN"

On this page