---
title: "Aggregate Accounts"
method: POST
path: "/crm/accounts/aggregate"
tags: ["CRM Service Calls", "CRM Aggregate"]
---

# Aggregate Accounts

`POST /crm/accounts/aggregate`

## Request

- Base URL: `https://fapi.ambivo.com` (the document declares no server; this is the origin it was published from)
- URL: `https://fapi.ambivo.com/crm/accounts/aggregate`
- Auth: API key in header `Authorization`
- TypeScript: <https://skmtc.dev/ambivo/apis/ambivo-api/docs/crm/accounts/aggregate/post.ts> (a function with typed inputs; its response is checked against the schema)

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

Use this endpoint to build account distribution charts by status, relationship type,
or industry. Pair with a numeric `aggregate_field` for revenue or employee-count roll-ups.

**Request Body (AggregateRequest):** Same as leads/aggregate.

**Examples:**
- Accounts by status: `{"group_by_fields": ["status"]}`
- Accounts by relationship type: `{"group_by_fields": ["relationship_type"]}`
- Accounts by industry with revenue: `{"group_by_fields": ["industry"], "aggregate_field": "revenue"}`

## Request body

- AggregateRequest: Request body for aggregate/group-by queries.
  - `group_by_fields` string[], required: Fields to group by, e.g. ["lead_status"], ["stage", "marketing_source"]
  - `aggregate_field` string, nullable: Numeric field to aggregate, e.g. "value_of_sale", "estimated_budget"
  - `match_filter_dict` string, nullable: JSON-stringified MongoDB filter to narrow the dataset before aggregation
  - `sort_dict` string, nullable: JSON-stringified sort criteria, e.g. {"count": -1}
  - `page_size` integer: Maximum number of groups to return
  - `page_num` integer: Page number (1-indexed)

## Response `200`

Successful Response

- AggregateResponse: Response for aggregate queries.
  - `groups` AggregateGroup[]: List of aggregate groups
    - `group_by` string: Human-readable label e.g. "Status: contacted"
    - `group_by_values` object, nullable: Programmatic values e.g. {"lead_status": "contacted"}
    - `count` integer: Number of records in this group
    - `total_value` number, nullable: Sum of aggregate_field
    - `avg_value` number, nullable: Average of aggregate_field
    - `max_value` number, nullable: Max of aggregate_field
    - `min_value` number, nullable: Min of aggregate_field
    - `entity_ids_list` unknown[], nullable: List of entity IDs in this group
      - unknown
  - `total_groups` integer: Total number of groups returned
  - `aggregate_field` string, nullable: The numeric field that was aggregated
  - `group_by_fields` string[]: Fields that were grouped by

## Other responses

- `422`: Validation Error

## Changes

- **2026-08-06** `165a6d16a9a0`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/ambivo/apis/ambivo-api/changes/crm/accounts/aggregate/post.md)

---

[API](https://skmtc.dev/ambivo/apis/ambivo-api.md) - [All operations](https://skmtc.dev/ambivo/apis/ambivo-api/llms.txt) - [OpenAPI document](https://skmtc.dev/ambivo/apis/ambivo-api/revisions/165a6d16a9a0?raw)
