Skip to main content

Hello,

I am trying to use the Query metric aggregates endpoint to download aggregated data, but I am getting inconsistent results when using or not using the “by” parameter for partitioning. When I request aggregated data for a certain period where no values are present, the endpoint returns a JSON with individual aggregated dates, and for each, the corresponding aggregated value is 0.0. However, if I add the “by” parameter for partitioning within the same period, the endpoint returns the correct number of dates, but only one aggregated value of 0.0. I am not sure how to interpret this result, as I expected the number of aggregated values to match the number of returned dates, but in this case, it does not.

Example without “by” parametr

REQUEST

{
"data":{
"type":"metric-aggregate",
"attributes":{
"interval":"day",
"page_size":500,
"timezone":"UTC",
"measurements":a
"count"
],
"filter":
"greater-or-equal(datetime,2024-09-22T00:00:00)",
"less-than(datetime,2024-09-30T00:00:00)"
],
"metric_id":"ShBCif",
"by":

]
}
}
}

RESPONSE

{
"data":{
"type":"metric-aggregate",
"id":"-3097399037002004947",
"attributes":{
"dates":
"2024-09-22T00:00:00+00:00",
"2024-09-23T00:00:00+00:00",
"2024-09-24T00:00:00+00:00",
"2024-09-25T00:00:00+00:00",
"2024-09-26T00:00:00+00:00",
"2024-09-27T00:00:00+00:00",
"2024-09-28T00:00:00+00:00",
"2024-09-29T00:00:00+00:00"
],
"data":
{
"dimensions":d

],
"measurements":{
"count":
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
}
}
]
},
"links":{
"self":"<https://a.klaviyo.com/api/metric-aggregates/>"
}
},
"links":{
"self":"<https://a.klaviyo.com/api/metric-aggregates/>",
"next":null,
"prev":null
}
}

 

Example WITH “by” parametr

REQUEST

{
"data":{
"type":"metric-aggregate",
"attributes":{
"interval":"day",
"page_size":500,
"timezone":"UTC",
"measurements":
"count"
],
"filter":
"greater-or-equal(datetime,2024-09-22T00:00:00)",
"less-than(datetime,2024-09-30T00:00:00)"
],
"metric_id":"ShBCif",
"by":
"Campaign Name"
]
}
}
}

RESPONSE

{
"data":{
"type":"metric-aggregate",
"id":"-1187976627318456868",
"attributes":{
"dates":
"2024-09-22T00:00:00+00:00",
"2024-09-23T00:00:00+00:00",
"2024-09-24T00:00:00+00:00",
"2024-09-25T00:00:00+00:00",
"2024-09-26T00:00:00+00:00",
"2024-09-27T00:00:00+00:00",
"2024-09-28T00:00:00+00:00",
"2024-09-29T00:00:00+00:00"
],
"data":>
{
"dimensions":
""
],
"measurements":{
"count":
0.0
]
}
}
]
},
"links":{
"self":"<https://a.klaviyo.com/api/metric-aggregates/>"
}
},
"links":{
"self":"<https://a.klaviyo.com/api/metric-aggregates/>",
"next":null,
"prev":null
}
}

Thank you for help.

!-->

Hi @hokul

 

The metric with that id you shared in the screenshot is “Marked Email as Spam” and it appears there are no events at all in the requested time range. If you group by Campaign Name, the only "value" is null. It appears you are not using the right metric id. I hope this helps! 

~Chloe

 


Reply