Solved

Metric Aggregate Endpoint - Ordered Product by Campaign


Badge +1

Hello,

 

Below is my payload for https://a.klaviyo.com/api/metric-aggregates/, however I do not get the data back broken down by campaign. However the same payload works for a different metric like “Clicked Email”

{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "metric_id": "HnmbpY",
            "measurements": ["count","unique","sum_value"],
      "interval": "day",
      "page_size": 1000,
      "timezone": "America/New_York",
            "by": ["Campaign Name"],
              "filter": [  
                  "greater-or-equal(datetime,2024-02-01)",  
                  "less-than(datetime,2024-02-29)"
              ]
    }
    }
}

 

Below are payload results:

 

Goal is to retrieve sum_value (dollar amounts) for below metrics at campaign level for given dates.

 

Thanks,

Shikha

icon

Best answer by saulblum 6 March 2024, 00:38

View original

17 replies

Userlevel 4
Badge +7

Try using "$attributed_message” as the “by” value, since events like Ordered Product are attributed to a campaign (or flow) message based on the attribution window you have set in your account.

https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes

Badge +1

@saulblum Thank you so much!

So "$attributed_message”  works for “Ordered Product”, but it does not work for “Opened Email”. “Opened Email” works when using by: "Campaign Name"

So if I am understanding it correct, some events work with "$attributed_message”  and some work with "Campaign Name".

Do you have a list of which events work with "$attributed_message” and which work with "Campaign Name"?

I am trying to pull all three measurements for all events(metrics) at day, campaign and flow level. So I need to determine which ones need "$attributed_message” and which ones need “Campaign Name" for metric aggregate endpoint. 

Your help is greatly appreciated to migrate to new API.

 

Thanks,

Shikha

 

Userlevel 4
Badge +7

Events tied directly to specific emails — Opened Email, Clicked Email, etc. — will use Campaign Name. Events that are not tied to specific messages but which can be attributed to a message — e.g. I placed an order three days after opening a campaign email — will use the “attributed” properties.

Badge +1

Is there a full list you can share on events:

  1. tied directly to specific emails and 
  2. Events that are not tied to specific messages but which can be attributed to a message
Userlevel 4
Badge +7

They’re listed at https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes

Badge +1

Hi, 

I have a follow up question:

Using below payload for Flow:

For Ordered Product metric, the sum_value returned for the above flow does not seem to match the API. What am I doing wrong here?

 

 

Userlevel 4
Badge +7

Hi, the difference is probably from how the API and the UI are treating dates.

For the API call, you are looking at all Ordered Product events on 1/1/24, and then getting the sum of those events attributed to the flow in question.

When you look at the flows report, you are looking at all flow emails sent on 1/1/24, and then getting the sum of orders attributed to the flow.

So if the flow sent me an email on 1/1/24 and I placed an order on 1/3/24, it would not be counted in the API call, but would be in the UI report.

There’s a new reporting API that will get you results that match those in the UI: https://developers.klaviyo.com/en/reference/query_flow_values

Badge +1

Thank you! This helps. 

So to be clear, the metric aggregates provides data by the date the event happened and the Reporting API provides data by the date the email is sent (via campaign or flow), Is my understanding correct? Is there any formal documentation that I can use to clear this up with my business.

Follow up question: On the reporting API, is it possible to break the data down by date when a range is given?

 

Userlevel 4
Badge +7

Correct, one is tracking when conversion events — e.g. Ordered Product — happened in a specified time frame, the other is tracking when messages were sent in a time frame, that led to conversion events.

Follow up question: On the reporting API, is it possible to break the data down by date when a range is given?

I think the flow series report will do this. Here’s a doc that was given to early testers of the reporting API: https://docs.google.com/document/d/1Ca8asJWWNiDJJODMsIrn1l40NthKDww64GwgqUGRg1s/edit

Badge +1

Hi There,

Would you please let me know what am I doing wrong here. The numbers from the API don’t seem to match for certain metrics. For 3/14/2024, the total Opened email is 96 for this campaign, however the API is giving 70.

Old API on the other hand matches to the UI:

However the received emails are good:
 

 

Thanks for you help!

Shikha

Userlevel 4
Badge +7

Heads up, you’re showing a private API key in a screenshot, I’d suggest you delete the screenshot and remove the private key from your account.

Badge +1

Thanks, screenshot updated

Badge +1

couple more questions:

How can I get the data from API, presented in this screen shot. Placed Order by Campaign:

 

I can get Placed Order by Attributed Message, but where in UI do I see the messages tied to the campaign?

Also what does below mean? “NgAhEY” is not an attributed message id?

 

Badge +1

Hi There. Wondering if I can get response for above issues. Your help is greatly appreciated!

Userlevel 7
Badge +36

Hi @shikha.agrawal!

My apologies for the delay here. To match the dashboards in the Klaviyo app with the API, I would recommend using our new Reporting API instead of the Query Metric Aggregates endpoint. 

 

This is because the new Reporting API endpoints pull from the same resource as the UI, so you won’t experience the discrepancy you see with the QMA endpoint. 

 

With the Reporting API, you can use the Query Campaign Values endpoint to retrieve conversion metrics:

 

Hope this helps!

Best,

Brian

Badge +1

Hi There. Thank you for your responses so far.

 

One quick question, we use private key for authentication. Will this still be supported with new API. So far it’s working, but just want to make sure private keys are not deprecating. 

 

Thanks,

Shikha

Badge +1

Hi There,

Got another question. I can get below data from API using $message attribute in metric aggregate endpoint. However I am unable to find what endpoint to use to map message id (VQkNQY) to it’s message name (WelcomeMessage). Would you please let me know how I can get this mapping?

 

Thanks,

Shikha

Reply