---
title: "Query Metric Aggregates"
description: "How to call Query Metric Aggregates (POST /api/metric-aggregates) in the Klaviyo REST API: authentication, parameters, request and response bodies, and an example request."
url: "https://developers.klaviyo.com/en/reference/query_metric_aggregates"
revision: "2026-10-15"
operationId: "query_metric_aggregates"
aliases: ["create_metric_aggregate"]
method: "POST"
endpoint: "https://a.klaviyo.com/api/metric-aggregates"
authentication: "privateKey"
scopes: ["metrics:read"]
rateLimits: {"burst":"3/s","steady":"60/m"}
revisionHeader: {"name":"revision","required":true}
deprecated: false
openApi: "https://raw.githubusercontent.com/klaviyo/openapi/2026-10-15/openapi/stable/apis/query_metric_aggregates.json"
jsonApi: {"fields":{"metric-aggregate":["data","dates","id"]}}
related: ["https://developers.klaviyo.com/en/reference/metrics/llms.txt","https://developers.klaviyo.com/en/reference/get_metrics.md","https://developers.klaviyo.com/en/reference/get_metric.md","https://developers.klaviyo.com/en/reference/get_metric_property.md","https://developers.klaviyo.com/en/reference/get_flows_triggered_by_metric.md","https://developers.klaviyo.com/en/reference/get_ids_for_flows_triggered_by_metric.md","https://developers.klaviyo.com/en/reference/get_properties_for_metric.md","https://developers.klaviyo.com/en/reference/get_property_ids_for_metric.md","https://developers.klaviyo.com/en/reference/get_metric_for_metric_property.md","https://developers.klaviyo.com/en/reference/get_metric_id_for_metric_property.md"]
---

# Query Metric Aggregates

> This is the Markdown version of https://developers.klaviyo.com/en/reference/query_metric_aggregates

```http
POST https://a.klaviyo.com/api/metric-aggregates
```

Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events (not to be confused with [custom metrics](https://developers.klaviyo.com/en/reference/metrics.md), which are not supported at this time). Queries must be passed in the JSON body of your `POST` request.

To request campaign and flow performance data that matches the data shown in Klaviyo's UI, we recommend the [Reporting API](https://developers.klaviyo.com/en/reference/reporting.md).

Results can be filtered and grouped by time, event, or profile dimensions.

To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint.md).

For a comprehensive list of request body parameters, native Klaviyo metrics, and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes.md).

- Revision header: `revision: 2026-10-15` (required)
- Scopes: `metrics:read`
- Rate limits: Burst: `3/s`, Steady: `60/m`
- OpenAPI: [Download this endpoint's OpenAPI document](https://raw.githubusercontent.com/klaviyo/openapi/2026-10-15/openapi/stable/apis/query_metric_aggregates.json)

## Example request

### curl

```bash
curl --request POST \
     --url 'https://a.klaviyo.com/api/metric-aggregates' \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/vnd.api+json' \
     --header 'revision: 2026-10-15' \
     --header 'content-type: application/vnd.api+json' \
     --data '{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "0rG4eQ",
      "measurements": [
        "count"
      ],
      "interval": "day",
      "page_size": 500,
      "by": [
        "$message"
      ],
      "filter": [
        "greater-or-equal(datetime,2022-12-01T00:00:00)",
        "less-than(datetime,2022-12-08T00:00:00)"
      ],
      "timezone": "America/New_York"
    }
  }
}'
```

### CLI

```bash
klaviyo metrics query-metric-aggregates \
  -d '{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "0rG4eQ",
      "measurements": [
        "count"
      ],
      "interval": "day",
      "page_size": 500,
      "by": [
        "$message"
      ],
      "filter": [
        "greater-or-equal(datetime,2022-12-01T00:00:00)",
        "less-than(datetime,2022-12-08T00:00:00)"
      ],
      "timezone": "America/New_York"
    }
  }
}'
```

Sign in first with `klaviyo auth login`. [Install the Klaviyo CLI](https://developers.klaviyo.com/en/docs/klaviyo_cli.md)

### Python

```python
from klaviyo_api import KlaviyoAPI

klaviyo = KlaviyoAPI("your-private-api-key")

response = klaviyo.Metrics.query_metric_aggregates(
    {
        "data": {
            "type": "metric-aggregate",
            "attributes": {
                "metric_id": "0rG4eQ",
                "measurements": [
                    "count",
                ],
                "interval": "day",
                "page_size": 500,
                "by": [
                    "$message",
                ],
                "filter": [
                    "greater-or-equal(datetime,2022-12-01T00:00:00)",
                    "less-than(datetime,2022-12-08T00:00:00)",
                ],
                "timezone": "America/New_York",
            },
        },
    },
)
```

Install it with `pip install klaviyo-api`. [The Python SDK on GitHub](https://github.com/klaviyo/klaviyo-api-python)

### Node.js

```javascript
import { ApiKeySession, MetricsApi } from 'klaviyo-api'

const session = new ApiKeySession('your-private-api-key')
const metricsApi = new MetricsApi(session)

const response = await metricsApi.queryMetricAggregates(
  {
    data: {
      type: 'metric-aggregate',
      attributes: {
        metricId: '0rG4eQ',
        measurements: [
          'count',
        ],
        interval: 'day',
        pageSize: 500,
        by: [
          '$message',
        ],
        filter: [
          'greater-or-equal(datetime,2022-12-01T00:00:00)',
          'less-than(datetime,2022-12-08T00:00:00)',
        ],
        timezone: 'America/New_York',
      },
    },
  },
)
```

Install it with `npm install klaviyo-api`. [The Node.js SDK on GitHub](https://github.com/klaviyo/klaviyo-api-node)

### Ruby

```ruby
require 'klaviyo-api-sdk'

KlaviyoAPI.configure do |config|
  config.api_key['Klaviyo-API-Key'] = 'Klaviyo-API-Key your-private-api-key'
end

response = KlaviyoAPI::Metrics.query_metric_aggregates(
  {
    data: {
      type: 'metric-aggregate',
      attributes: {
        metric_id: '0rG4eQ',
        measurements: [
          'count',
        ],
        interval: 'day',
        page_size: 500,
        by: [
          '$message',
        ],
        filter: [
          'greater-or-equal(datetime,2022-12-01T00:00:00)',
          'less-than(datetime,2022-12-08T00:00:00)',
        ],
        timezone: 'America/New_York',
      },
    },
  },
)
```

Install it with `gem install klaviyo-api-sdk`. [The Ruby SDK on GitHub](https://github.com/klaviyo/klaviyo-api-ruby)

### PHP

```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');

use KlaviyoAPI\KlaviyoAPI;

$klaviyo = new KlaviyoAPI('your-private-api-key');

$response = $klaviyo->Metrics->queryMetricAggregates(
    [
        'data' => [
            'type' => 'metric-aggregate',
            'attributes' => [
                'metric_id' => '0rG4eQ',
                'measurements' => [
                    'count',
                ],
                'interval' => 'day',
                'page_size' => 500,
                'by' => [
                    '$message',
                ],
                'filter' => [
                    'greater-or-equal(datetime,2022-12-01T00:00:00)',
                    'less-than(datetime,2022-12-08T00:00:00)',
                ],
                'timezone' => 'America/New_York',
            ],
        ],
    ],
);
```

Install it with `composer require klaviyo/api`. [The PHP SDK on GitHub](https://github.com/klaviyo/klaviyo-api-php)

## Query parameters

- `fields[metric-aggregate]` (string[]): For more information please visit [API overview](https://developers.klaviyo.com/en/reference.md) Allowed values: `data`, `dates`, `id`

## Headers

- `revision` (string, required): API endpoint revision (format: YYYY-MM-DD[.suffix]) Default: `2026-10-15`

## Request body

Content type: `application/vnd.api+json` (required)

- `data` (object, required)
  - `type` (string, required): Allowed values: `metric-aggregate`
  - `attributes` (object, required)
    - `metric_id` (string, required): The metric ID used in the aggregation. Example: `0rG4eQ`
    - `page_cursor` (string): Optional pagination cursor to iterate over large result sets
    - `measurements` (string[], required): Measurement key, e.g. `unique`, `sum_value`, `count` Allowed values: `count`, `sum_value`, `unique`
    - `interval` (string, nullable): Aggregation interval, e.g. "hour", "day", "week", "month" Allowed values: `day`, `hour`, `month`, `week` Default: `day` Example: `day`
    - `page_size` (integer, nullable): Alter the maximum number of returned rows in a single page of aggregation results Default: `500` Example: `500`
    - `by` (string[], nullable): Optional attribute(s) used for partitioning by the aggregation function Allowed values: `$attributed_channel`, `$attributed_flow`, `$attributed_message`, `$attributed_variation`, `$campaign_channel`, `$flow`, `$flow_channel`, `$message`, `$message_send_cohort`, `$usage_amount`, `$value_currency`, `$variation`, `$variation_send_cohort`, `Bot Click`, `Bounce Type`, `Campaign Name`, `Client Canonical`, `Client Name`, `Client Type`, `Email Domain`, `Failure Source`, `Failure Type`, `From Number`, `From Phone Region`, `Inbox Provider`, `List`, `Message Format`, `Message Name`, `Message Type`, `Method`, `Segment Count`, `Subject`, `To Number`, `To Phone Region`, `URL`, `form_id`
    - `return_fields` (string[], nullable): Provide fields to limit the returned data
    - `filter` (string[], required): List of filters, must include time range using ISO 8601 format (YYYY-MM-DDTHH:MM:SS.mmmmmm).
                  These filters follow a similar format to those in `GET` requests, the primary difference is that this endpoint asks for a list.
                  The time range can be filtered by providing a `greater-or-equal` and a `less-than` filter on the `datetime` field.
    - `timezone` (string, nullable): The timezone used for processing the query, e.g. `'America/New_York'`.
                  This field is validated against a list of common timezones from the [IANA Time Zone Database](https://www.iana.org/time-zones).
                  While most are supported, a few notable exceptions are `Factory`, `Europe/Kyiv` and `Pacific/Kanton`. This field is case-sensitive. Default: `UTC` Example: `America/New_York`
    - `sort` (string): Provide a sort key (e.g. -$message) Allowed values: `$attributed_channel`, `-$attributed_channel`, `$attributed_flow`, `-$attributed_flow`, `$attributed_message`, `-$attributed_message`, `$attributed_variation`, `-$attributed_variation`, `$campaign_channel`, `-$campaign_channel`, `$flow`, `-$flow`, `$flow_channel`, `-$flow_channel`, `$message`, `-$message`, `$message_send_cohort`, `-$message_send_cohort`, `$usage_amount`, `-$usage_amount`, `$value_currency`, `-$value_currency`, `$variation`, `-$variation`, `$variation_send_cohort`, `-$variation_send_cohort`, `Bot Click`, `-Bot Click`, `Bounce Type`, `-Bounce Type`, `Campaign Name`, `-Campaign Name`, `Client Canonical`, `-Client Canonical`, `Client Name`, `-Client Name`, `Client Type`, `-Client Type`, `Email Domain`, `-Email Domain`, `Failure Source`, `-Failure Source`, `Failure Type`, `-Failure Type`, `From Number`, `-From Number`, `From Phone Region`, `-From Phone Region`, `Inbox Provider`, `-Inbox Provider`, `List`, `-List`, `Message Format`, `-Message Format`, `Message Name`, `-Message Name`, `Message Type`, `-Message Type`, `Method`, `-Method`, `Segment Count`, `-Segment Count`, `Subject`, `-Subject`, `To Number`, `-To Number`, `To Phone Region`, `-To Phone Region`, `URL`, `-URL`, `count`, `-count`, `form_id`, `-form_id`, `sum_value`, `-sum_value`, `unique`, `-unique`

### Example request body

```json
{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "0rG4eQ",
      "measurements": [
        "count"
      ],
      "interval": "day",
      "page_size": 500,
      "by": [
        "$message"
      ],
      "filter": [
        "greater-or-equal(datetime,2022-12-01T00:00:00)",
        "less-than(datetime,2022-12-08T00:00:00)"
      ],
      "timezone": "America/New_York"
    }
  }
}
```

## Responses

### 200: Success

Content type: `application/vnd.api+json`

- `data` (object, required)
  - `type` (string, required): Allowed values: `metric-aggregate`
  - `id` (string, required): Ephemeral ID associated with the aggregation query
  - `attributes` (object, required)
    - `dates` (string<date-time>[], required): The dates of the query range
    - `data` (object[], required): Aggregation result data
      - `dimensions` (string[], required): List of dimensions associated with this set of measurements
      - `measurements` (object, required): Dictionary of measurement_key, values
  - `links` (object, required)
    - `self` (string<uri>, required)
- `links` (ObjectLinks): Same fields as the first ObjectLinks above.
- `meta` (object): Response-level metadata
  - `agent_hints` (object): Optional hints emitted by the API for agent callers
    - `next_steps` (string[]): Suggested follow-up actions for agents to take after this response

#### Example response body

```json
{
  "data": {
    "type": "metric-aggregate",
    "id": "string",
    "attributes": {
      "dates": [
        "2026-01-01T00:00:00+00:00"
      ],
      "data": [
        {
          "dimensions": [
            "string"
          ],
          "measurements": {}
        }
      ]
    },
    "links": {
      "self": "https://www.example.com"
    }
  },
  "links": {
    "self": "https://www.example.com"
  },
  "meta": {
    "agent_hints": {
      "next_steps": [
        "string"
      ]
    }
  }
}
```

### 4XX: Client Error

Content type: `application/vnd.api+json`

- `errors` (object[], required)
  - `id` (string, required)
  - `code` (string, required)
  - `title` (string, required)
  - `detail` (string, required)
  - `source` (object)
    - `pointer` (string)
    - `parameter` (string)

#### Example response body

```json
{
  "errors": [
    {
      "id": "string",
      "code": "string",
      "title": "string",
      "detail": "string",
      "source": {
        "pointer": "string",
        "parameter": "string"
      }
    }
  ]
}
```

### 5XX: Server Error

Content type: `application/vnd.api+json`

- `errors` (object[], required)
  - `id` (string, required)
  - `code` (string, required)
  - `title` (string, required)
  - `detail` (string, required)
  - `source` (object)
    - `pointer` (string)
    - `parameter` (string)

#### Example response body

```json
{
  "errors": [
    {
      "id": "string",
      "code": "string",
      "title": "string",
      "detail": "string",
      "source": {
        "pointer": "string",
        "parameter": "string"
      }
    }
  ]
}
```
