Solved

Flow, Campaign Metrics from API

  • 19 October 2021
  • 9 replies
  • 1776 views

Badge +2

I see that this question has been asked a few time, but the answers were a little general. I was wondering exactly which endpoint will allow me to pull conversions and conversion values for campaigns and flows?

Is there an endpoint that will allow me to pull campaign metrics directly? Or is there a more indirect way of achieving this?

I know there is no direct API for flows, so I would hit the lists API first to get email ID’s associated with each flow and then cross reference with timeline? Which event should I be cross referencing with?

icon

Best answer by David To 21 October 2021, 20:08

View original

9 replies

Userlevel 7
Badge +60

Hello@ppcorp,

Wonderful question!

You can actually utilize Klaviyo’s /export endpoint as part of the Metric’s API while leveraging the ID of your conversion metric within your account to return both your campaign and flow revenue via API. 

In the request, you'd also want to specify in the "measurement" parameter that you're specifically looking for the "value", which returns the amount of revenue, and also specify in the "where" filter the campaign ID that the metric is attributed to with "$attributed_message". When calling for a flow’s conversion data, you’ll want to use the flow ID that the metric is attributed to with “$attributed_flow” instead. 

You can find more of these example requests from the  How to Export Conversion Data Help Center article in addition to our API Documentation for this particular Export Endpoint. For convenience, you can see the example requests below:

Campaigns:

curl https://a.klaviyo.com/api/v1/metric/PLACEDORDERMETRIC/export -G \
-d api_key=API_KEY \
-d unit='week' \
-d measurement='value' \
-d where='[["$attributed_message","=",'MESSAGE_ID']]'

Flows:

curl https://a.klaviyo.com/api/v1/metric/METRIC_ID/export -G \
-d api_key=API_KEY \
-d measurement='value' \
-d where='[["$attributed_flow","=",'FLOW_ID']]'

I hope this helps!

David

Badge +2

Thank you for that explanation, that was a huge help. I now can get the campaign metrics by message ID. What endpoint can I hit to get a list of available flows? 

 

Thanks!

Joe

Userlevel 7
Badge +60

Hey @ppcorp,

Glad that was helpful!

Although undocumented, you can use the a.klaviyo.com/api/v1/flows?api_key=****** endpoint to return a list of flows in your Klaviyo account. Some other hidden endpoints related to flows that may prove helpful are:

Single flow: 
https://a.klaviyo.com/api/v1/flow/FLOW_ID?api_key=******

Single flow with actions:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/actions?api_key=******

Single action from a flow:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID?api_key=******

Email that was used for flow action of sending email:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID/email?api_key=******

Have a great day!

David

Badge +1

hi @David To  i am trying to use this but even when the call is successfully done the answer is giving me all 0 cero values , even when i know that those flows ids or messages id have values 

here my call

https://a.klaviyo.com/api/v1/metric/X8K8GZ/export?start_date=2021-11-01&end_date=2021-11-30&unit=week&measurement=value&where=%5B%5B%22%24attributed_message%22%2C%22%3D%22%2C%22Wf6rLC%22%5D%5D&api_key=MYAPIKEY

 

Userlevel 7
Badge +60

Hey @Jolguer,

Technically speaking that value response of [0.0] you are seeing is actually correct. This is because when trying to make a call for the Clicked Email metric, that metric doesn’t record a value as a measurement. Instead, you’ll want to define the measurement as unique or count. Similarly, instead of defining the where parameter as $attributed_flow, you’ll want to use either $flow or $message depending on what your goal was.

Overall, it doesn’t seem like you’ve structured the call correctly to align with the specific metric you were trying to query for but rather kept a number of the parameters the same as the ones used to retrieve conversion (Placed order/revenue) data. I would suggest taking a further look at our Query Event Data and Native Klaviyo Metrics & Attributes references in the Developer’s Portal for a better understanding on how to structure these calls based on individual metrics. 

You can also find an example call structure to retrieve the the number of clicks in the Unique Clicks (unique_clicks) section of the How to Export Conversion Data Help Center article previously provided which I’ve also included below:

curl https://a.klaviyo.com/api/v1/metric/CLICKED_EMAIL_METRIC_ID/export -G \
-d api_key=API_KEY \
-d unit='week' \
-d measurement='unique' \
-d where='[["$message","=",'MESSAGE_ID']]'

I hope this helps!

David

Badge

Hey @ppcorp,

Glad that was helpful!

Although undocumented, you can use the a.klaviyo.com/api/v1/flows?api_key=****** endpoint to return a list of flows in your Klaviyo account. Some other hidden endpoints related to flows that may prove helpful are:

Single flow: 
https://a.klaviyo.com/api/v1/flow/FLOW_ID?api_key=******

Single flow with actions:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/actions?api_key=******

Single action from a flow:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID?api_key=******

Email that was used for flow action of sending email:
https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID/email?api_key=******

Have a great day!

David

Hi David,

I’m trying to get a simple dump of flow ids and names… running:

a.klaviyo.com/api/v1/flows?api_key=******

now errors with: 

{

"status": 400,

"message": "This request is missing the following required params: \"name\"."

}

other suggestions?

Thanks in advance!

  • Team Cohley!
Badge

GET… not a POST… got it…. now it works!

Badge +1

@David To thanks for sharing the non-documented flow API!

 

One question: I am trying to get the email body/ html from actions in flows, but it doesn’t appear to be returned from https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID/email

 

Only to/from, sender, etc…

 

Is there a way to get the email html for flow actions via the API? Some ID I can grab from these Flow APIs and pass to the template API or something else?

 

Thanks,

Daniel

Userlevel 7
Badge +60

Hey @daniellanger,

This currently is a limitation pertaining to the undocumented flows V1 endpoint. Since our Product Team is looking for feedback as they actively work to introduce V3 of our API endpoint, I’ll share your use case and details with them! I know that from speaking to that team that improving upon these originally undocumented Flows V1 endpoint was a big focus for them.

If you haven’t already, you can also sign up to be an early beta tester of the V3 API endpoints and uncover some of these new improvements by joining our V3 API Beta List here

David

Reply