v1

latestOpenAPI 3.1.02026-08-069158174.8 KB
CRM Service Calls
CRM Aggregate

Aggregate Leads

Aggregate leads by group-by fields — ideal for dashboards, charts, and analytics.

Use this endpoint to generate counts, sums, averages, min/max grouped by one or more lead fields. Perfect for building pie charts (leads by status), bar charts (leads by source), or summary tables with numeric roll-ups.

Request Body (AggregateRequest):

  • group_by_fields (required): Fields to group by, e.g. ["lead_status"] or ["lead_source", "lead_status"].
  • aggregate_field (optional): Numeric field to compute sum/avg/min/max for, e.g. "estimated_budget".
  • match_filter_dict (optional): JSON-stringified MongoDB filter to narrow the dataset before aggregation. Use exact database field names only. Example: {"lead_source": "Google"} — aggregate only Google leads.
  • sort_dict (optional): JSON sort criteria, e.g. {"count": -1} for most to least.
  • page_size (default: 50): Max groups to return.

Response: Array of groups, each with group_by label, count, and optional total_value, avg_value, max_value, min_value, plus entity_ids_list.

Examples:

  • Leads by status: {"group_by_fields": ["lead_status"]}
  • Leads by source with budget: {"group_by_fields": ["lead_source"], "aggregate_field": "estimated_budget"}
post/crm/leads/aggregate

Request body

group_by_fieldsstring[] required

Fields to group by, e.g. ["lead_status"], ["stage", "marketing_source"]

aggregate_fieldstring nullable

Numeric field to aggregate, e.g. "value_of_sale", "estimated_budget"

match_filter_dictstring nullable

JSON-stringified MongoDB filter to narrow the dataset before aggregation

sort_dictstring nullable

JSON-stringified sort criteria, e.g. {"count": -1}

page_sizeinteger

Maximum number of groups to return

page_numinteger

Page number (1-indexed)

Response

Successful Response

total_groupsinteger

Total number of groups returned

aggregate_fieldstring nullable

The numeric field that was aggregated

group_by_fieldsstring[]

Fields that were grouped by