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
| Parameter | Type | Description |
|---|---|---|
object | string | The object to aggregate (e.g., opportunities, contacts) |
Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
field | string | Yes | The field to aggregate (e.g., amount, id, status) |
function | string | Yes | Aggregation function: COUNT, SUM, AVG, MIN, MAX, COUNT_DISTINCT |
group_by | string | No | Field to group results by |
filter_field | string | No | Field to filter on before aggregating |
filter_operator | string | No | Filter operator (e.g., equals, gt, lt, contains, is_null) |
filter_value | string | No | Value for the filter |
Validation rules
- The
fieldmust exist on the target object. SUMandAVGare 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, andMAXwork on any field type.- When
filter_fieldis provided,filter_operatorandfilter_valueare 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
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_OBJECT | The object name does not exist |
| 400 | VALIDATION_ERROR | The 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"