Skip to main content
Solved

Attribute Order Placed count & sum_value to Campaign / Flow


Hayvo
Contributor I
Forum|alt.badge.img
  • Contributor I
  • 2 replies

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": ["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

Best answer by Hayvo

Edit, 

I switched from $message to $attributed_message and got a workaround. 

 

Pierre 

Founder & Consultant @ DataGem Consulting

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

chloe.strange
Community Manager
Forum|alt.badge.img+41
  • Community Manager
  • 429 replies
  • August 20, 2024

Hi @Hayvo

Thanks for sharing. I would suggest putting the “by” in an array. In the developer portal you can find this information. 

On this page the by is in an array:
"by": ["$attribute"]

whereas in your message it is not in an array:
"by": "$message"
vs.
"by": ["$message"]

I hope this helps!

~Chloe


Hayvo
Contributor I
Forum|alt.badge.img
  • Author
  • Contributor I
  • 2 replies
  • August 26, 2024

Hi @chloe.strange 

Unfortunately I tried switching from a string to an array but nothing changed. 

This is weird because I can see the right numbers on the Klaviyo UI dashboard. 

That concerns every Shopify metrics not only the Placed Order one. 

 

Pierre 

Founder & Consultant @ DataGem Consulting


Hayvo
Contributor I
Forum|alt.badge.img
  • Author
  • Contributor I
  • 2 replies
  • Answer
  • August 27, 2024

Edit, 

I switched from $message to $attributed_message and got a workaround. 

 

Pierre 

Founder & Consultant @ DataGem Consulting