Skip to main content
Solved

How to get the value of "Revenue from Klaviyo" thru the API?

  • February 7, 2023
  • 3 replies
  • 749 views

Forum|alt.badge.img+3
  • Active Contributor I
  • 14 replies

Hi,

 

I was wondering how to get the value of the KPI “Revenue from Klaviyo”? I tried using the metric “Placed Orders” (with the “value” unit), and it appears to be the same value as “Total Revenue”. So I was wondering how to get “Revenue from Klaviyo” instead.

 

Is there also a way to get the value of “Purchases from Klaviyo” thru the API?

 

Thank you,

-Marie

Best answer by Brian Turcotte

Hi @Nymesia,

 

I checked in with Engineering, and it turns out that it’s not currently feasible to replicate the dashboard revenue via the APIs at this time, due to subtle differences in Klaviyo attribute revenue calculations.

 

However, this discrepancy is definitely on the Product Team’s radar, so I will update the thread if there are any updates to the endpoint that would allow for this.

 

Best,

Brian

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

3 replies

Brian Turcotte
Forum|alt.badge.img+37

Hi@Nymesia

 

An API request like the one pasted below allows you to query for a particular metric over a defined time-range, grouping by $attributed_message and $attributed_flow, and then summing up the $value property. The group by part $attributed_message and $attributed_flow is optional, but it shows how you could break out flows from campaigns ($attributed_message) vs. flows ($attributed_flow).

 

It’s also worth noting that you are required to return results grouped by some time period. In this example, we return results grouped by month. If you’d like to get a single value across all months, I would recommend gathering whatever code is responsible for issuing this request, and then take the response and aggregate it:

curl --location --request POST 'https://a.klaviyo.com/api/metric-aggregates/' \
--header 'Authorization: Klaviyo-API-Key redacted' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'revision: 2022-10-17' \
--data-raw '
{
     "data": {
          "type": "metric-aggregate",
          "attributes": {
               "measurements": [
                    "sum_value"
               ],
               "filter": [
                    "greater-or-equal(datetime,2022-11-13T00:00:00)",
                    "less-than(datetime,2022-12-13T23:59:59)",
                    "not(equals($attributed_message,\"\"))"
               ],
               "by": ["$attributed_message", "$attributed_flow"],
               "metric_id": "Wrg2NS",
               "interval": "month",
               "timezone": "EST"
          }
     }
}
' 
 

One other note:

  • in this request, under filter , a condition is included that evaluates whether $attributed_message equals a blank string \"\".
  • Eventually, the there will be added support for evaluating null. When that time comes, it may be cleaner to revise that filter condition to be: "not(equals($attributed_message,null))".

 

I hope this helps, and thanks for using the Community!

- Brian


Forum|alt.badge.img+3
  • Author
  • Active Contributor I
  • 14 replies
  • February 8, 2023

Hey @Brian Turcotte!

 

Thanks a bunch for the explanation. Would you know what metric exactly would correspond to “Revenue From Klaviyo”? Is it a custom metric in the client’s account, or is it a default metric in Klaviyo? Or is it a filter I can apply when I query data?

 

Thank you,

Marie


Brian Turcotte
Forum|alt.badge.img+37
  • Klaviyo Alum
  • 1393 replies
  • Answer
  • February 22, 2023

Hi @Nymesia,

 

I checked in with Engineering, and it turns out that it’s not currently feasible to replicate the dashboard revenue via the APIs at this time, due to subtle differences in Klaviyo attribute revenue calculations.

 

However, this discrepancy is definitely on the Product Team’s radar, so I will update the thread if there are any updates to the endpoint that would allow for this.

 

Best,

Brian