Question: is it possible to pull aggregated metric (e.g. “Opened Email”, etc) data by list / segment from the https://a.klaviyo.com/api/metric-aggregates/ endpoint? If not, what are my options? One option I can think of is to pull the raw events and associate them with the lists but that seems quite a lot of work.
I am asking because I was able to do that segmentation in the reporting interface.
Context:
I was trying to pull aggregated metric data from the https://a.klaviyo.com/api/metric-aggregates/
endpoint.
With the following payload,
{
"data": {
"type": "metric-aggregate",
"attributes": {
"measurements": [
"count"
],
"filter": [
"greater-or-equal(datetime,2022-06-06 12:29:59+00:00)",
"less-than(datetime,2023-06-05 18:46:29+00:00)",
'any($message,["MESSAGE_ID1","MESSAGE_ID2"])'
],
"by": ["$message"],
"interval": "month",
"timezone": "US/Eastern",
"metric_id": "METRIC_ID"
}
}
}
I was able to get a response for the “Opened Email” metric.
{'data': {'type': 'metric-aggregate',
'id': 'xxx',
'attributes': {'dates': ['2022-06-01T04:00:00+00:00',
'2022-07-01T04:00:00+00:00',
'2022-08-01T04:00:00+00:00',
'2022-09-01T04:00:00+00:00',
'2022-10-01T04:00:00+00:00',
'2022-11-01T04:00:00+00:00',
'2022-12-01T05:00:00+00:00',
'2023-01-01T05:00:00+00:00',
'2023-02-01T05:00:00+00:00',
'2023-03-01T05:00:00+00:00',
'2023-04-01T04:00:00+00:00',
'2023-05-01T04:00:00+00:00',
'2023-06-01T04:00:00+00:00'],
'data': [{'dimensions': ['MESSAGE_ID1'],
'measurements': {'count': [0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2378.0,
347.0,
21.0,
0.0]}},
{'dimensions': ['MESSAGE_ID2'],
'measurements': {'count': [0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
599.0,
31.0,
0.0]}}]},
'links': {'self': 'https://a.klaviyo.com/api/metric-aggregates/'}},
'links': {'self': 'https://a.klaviyo.com/api/metric-aggregates/',
'next': None,
'prev': None}}
However, when I try to further segment the response by list / segment with the following payload (adding the additional “by” field parameter), I was not able to get the intended result. No further segmentation is given.
{
"data": {
"type": "metric-aggregate",
"attributes": {
"measurements": [
"count"
],
"filter": [
"greater-or-equal(datetime,2022-06-06 12:29:59+00:00)",
"less-than(datetime,2023-06-05 18:46:29+00:00)",
'any($message,["MESSAGE_ID1","MESSAGE_ID2"])'
],
"by": ["$message", "List"],
"interval": "month",
"timezone": "US/Eastern",
"metric_id": "METRIC_ID"
}
}
}