Query Metric Aggregates
POST {{baseUrl}}/api/metric-aggregates/
Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events. Queries must be passed in the JSON body of your POST
request.
Results can be filtered and grouped by time, event, or profile dimensions.
Request body parameters (nested under attributes
):
return_fields
: request specific fields using sparse fieldsetssort
: sort results by a specified field, such as"-timestamp"
page_cursor
: results can be paginated with cursor-based paginationpage_size
: limit the number of returned results per pageby
: optional attributes used to group by the aggregation function- When using
by
attributes, an emptydimensions
response is expected when the counts for the events do not have the associated dimension requested by the setby
attribute. For example, a query including"by": ["$flow"]
will return an empty dimensions response for counts of metrics not associated with a$flow
- When using
measurement
: the measurement key supports the following values:"sum_value"
: perform a summation of the_Event Value_
, optionally partitioned over any dimension provided in theby
field"count"
: counts the number of events associated to a metric, optionally partitioned over any dimension provided in theby
field"unique"
counts the number of unique customers associated to a metric, optionally partitioned over any dimension provided in theby
field
interval
: aggregation interval, such as"hour"
,"day"
,"week"
, and"month"
metric_id
: the metric ID used in the aggregationfilter
: list of filters for specific fields, must include time range using ISO 8601 format ("YYYY-MM-DDTHH:MM:SS.mmmmmm"
)- The time range can be filtered by providing a
greater_or_equal
filter on the datetime field, such as"greater-or-equal(datetime,2021-07-01T00:00:00)"
and aless-than
filter on the same datetime field, such as"less-than(datetime,2022-07-01T00:00:00)"
- The time range may span a maximum of one year. Time range dates may be set to a maximum of 5 years prior to the current date
- Filter the list of supported aggregate dimensions using the common filter syntax, such as
"equals(URL,\"https://www.klaviyo.com/\")"
- The time range can be filtered by providing a
timezone
: the timezone used when processing the query. Case sensitive. This field is validated against a list of common timezones from the IANA Time Zone Database
For a comprehensive list of native Klaviyo metrics and their associated attributes for grouping and filtering, please refer to the metrics attributes guide.
Rate limits:
Burst: 3/s
Steady: 60/m
Scopes:
Metrics Read
Request Body
{"data"=>{"type"=>"metric-aggregate", "attributes"=>{"metric_id"=>"ei", "measurements"=>["unique", "count"], "interval"=>"day", "filter"=>["in nisi tempor eiusmod", "in consectetur id veniam"], "timezone"=>"reprehenderit officia quis cupidatat", "page_size"=>12591945, "by"=>["From Phone Region", "$message"], "return_fields"=>["consectetur", "eiusmod ea sunt"], "sort"=>"-To Number", "page_cursor"=>"aliqua mollit et incididunt"}}}
HEADERS
Key | Datatype | Required | Description |
---|---|---|---|
revision | string | (Required) API endpoint revision (format: YYYY-MM-DD[.suffix]) | |
Content-Type | string | ||
Accept | string |
RESPONSES
status: Created
{"data":{"type":"metric-aggregate","id":"dolor ea","attributes":{"dates":["1975-10-12T22:07:04.326Z","1977-12-15T21:21:06.263Z"],"data":[{"dimensions":[{"value":"\u003cError: Too many levels of nesting to fake this schema\u003e"},{"value":"\u003cError: Too many levels of nesting to fake this schema\u003e"}],"measurements":{}},{"dimensions":[{"value":"\u003cError: Too many levels of nesting to fake this schema\u003e"},{"value":"\u003cError: Too many levels of nesting to fake this schema\u003e"}],"measurements":{}}]},"links":{"self":"https://pJeDUQlbMgBYPMxXB.skxaoKbjaAh9FLcq1Oia-Typ2NWpmlb8UywjHr2u1LJ+Qpl9bo.ml"}}}