Hi community !
I’ve been playing with the Klaviyo API for a while now and managed to accomplish many things. However, I am now facing an issue that I can’t seem to resolve.
After going through every related topics in the Community I still haven’t been able to solve my issue.
So the issue is the following
When using the /metric-aggregates/ endpoint I can’t attribute Flow or Campaign to the Placed Order metrics. What I am trying to do is to retrieve count & sum_value of Placed Order for each Campaign / Flow.
I precise that our Shopify store is fully integrated with Klaviyo so it shouldn’t be the source of the problem.
Here I provide the code that I am using to fetch the data.
url = f"https://a.klaviyo.com/api/metric-aggregates/"
headers = {"accept": "application/json",
"revision":"2024-07-15",
"content-type": "application/json",
"Authorization": f"Klaviyo-API-Key {self.PRIVATE_API_KEY}"}
payload = { "data":
{"type": "metric-aggregate",
"attributes": {"metric_id": ORDER_PLACED_METRIC_ID,
"interval": "day",
"page_size": 500,
"filter" : f"greater-or-equal(datetime,{startTime}),less-than(datetime,{endTime})"],
"measurements": i"count", "sum_value", "unique"],
"by": ‘$message’,
"page_size": 500,
"timezone": "America/New_York",}}
response = requests.post(url, headers=headers, json=payload).json()
It seems that no matter what I use in the “by” parameter, the response always returns NULL values for the groupby dimension.
The answer does return correct values for the global count and sum_value (the monthly total matches what I see on the dashboard), but now I can’t attribute the Revenue to the corresponding campaigns.
Anyone knows how to fix this ?
Thanks a lot,
Pierre
Founder & Consultant @ DataGem Consulting