Solved

API - Attribution regarding Placed order event


Badge +2

Hey Klaviyo community,

 

I’m trying to export my data from klaviyo in order to do analytics stuff.

Here what i want to achieve :

→ Allocate my event “placed_order” to a specific campaign / flow in my Airtable.

Klaviyo is connected to my Shopify store.


Do you know if there is a way to achieve this ?
I dig into the API documentation but nothing helped me.

 

Thanks for your help :relaxed:

Thomas.

icon

Best answer by jallain 16 March 2021, 19:56

View original

12 replies

Userlevel 4
Badge +11

@Thomas_Rodier thanks for the great question! Take a look at this article which I think may help:

 

https://help.klaviyo.com/hc/en-us/articles/360040093732-How-to-Export-Conversion-Data

 

This is likely the API documentation that will be relevant to your use case:

 

https://www.klaviyo.com/docs/api/metrics

 

Particularly the /export endpoint at the bottom of the page. Let me know if you had any other follow up questions or if these links weren’t helpful.

Badge +2

Thanks for your quick answer !

Let me clarify, here is what i get from the endpoint api/v1/metrics/PLACED_ORDER_ID/timeline
 

{
"event_properties": {
"$value": "99.00",
"$event_id": "myeventid",
"tags": [],
"$extra": {....
},
"Items": [
"My item"
],
"$attribution": {
"$message": "RtMgj4",
"$send_ts": "numberofmyts,
"$attributed_event_id": "myattributed_event_id"
},
"ShippingRate": "my shipping",
"Item Count": 1,
"Source Name": "web",
"Collections": [
....
],
"Discount Codes": [],
"$currency_code": "EUR",
"Total Discounts": "0.00"
},
"uuid": "my_uuid",
"event_name": "Placed Order",
"timestamp": 1615912485,
"object": "event",
"datetime": "2021-03-16 16:34:45+00:00",
"person": {....
},
"statistic_id": "my_statistic_id",
"id": "3nUuN4aK"
},

So i should use this endpoint to export in time range :

api/v1/metrics/PLACED_ORDER_ID/export -d where='[["$attributed_message","=",'MESSAGE_ID']]'

Where inside the doc $attributed_message is the $message in my JSON and the message_id is the campaign id, right ?

 

With Postman it worked, but i want to be sur that’s the good process !

 

And additionnal question, is it the same process for flows ?

 

Thanks for your time Jallain !
 

Userlevel 4
Badge +11

@Thomas_Rodier That looks like it should work for your first use case although I know that there can sometimes be a few different values to choose from in the spot that you used $attributed_message depending on whether it is a Campaign, Flow, or A/B Test Variation, and which conversion metric you are using.

 

So if you have any troubles getting the data you are looking for, try experimenting with: $attributed_flow, $message, $campaign, $flow, and $attributed_variation.

 

Hope that helps!

Badge +2

@jallain thanks !

 

Do you know if there is doc about those distinction in API way ? (Campaign, Flow, A/B test variation)
I want to be sur i’m not missing something :sweat_smile:

 

But it’s working for this specific use case !

Thanks for your time :grinning:

 

Userlevel 4
Badge +11

@Thomas_Rodier we are planning on updating our APIs and their documentation this year so hopefully we will have a more comprehensive list at that time. For now the link I shared earlier shows the use case of $message and $attributed_message.

$attributed_variation would only be useful in cases where you were doing an A/B test with different versions of an email.

$flow or $message would be useful to try for tracking opens as opposed to something like placed_orders.

Badge +2

Ok ! I can't wait to see it !

 

I have another question related to this topic and flows.

 

How can i retrieve all emails (don’t know how to name them as it’s not a campaign) linked to a flow ?
It will help a me lot to track placed_order related to flow’s email.

Because now, i don’t know how i should proceed.

 

Once again, thanks a lot for your time @jallain :grinning:

Userlevel 4
Badge +11

@Thomas_Rodier you can get a Flow with its Actions from the API with this URL

Get Single Flow w/ Actions: https://a.klaviyo.com/api/v1/flow/FLOW_ID?api_key=pk_****

That response should be an array of JSON objects that each represent an Action in the Flow. If you look at the “type” property of each Action, the ones that are labeled “SEND_MESSAGE” are emails. If you need to you can also use these other URLs for Flow related API requests:

 

Get Flows: https://a.klaviyo.com/api/v1/flows?api_key=pk_****

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

Get Single Flow Action: https://a.klaviyo.com/api/v1/flow/FLOW_ID/action/ACTION_ID?api_key=pk_****

Badge +2

@jallain thank you so much for this amazing answer :grinning:

 

One last question, juste to be sure :

Regarding informations i get in single_flow actions, there is only the ID of the action.

Nothing about a message_id that could be use to assign a placed_order event to this specific action (when it’s an email of course).

Here it’s the JSON i get for a specific flow with a message inside : (this endpoint api/v1/flow/FLOW_ID/actions?api_key=pk_*******)

[
{
"status": "live",
"delay_seconds": 0,
"created": "2020-11-24 09:52:32",
"send_time": "None",
"object": "flow-action",
"updated": "2021-01-27 09:07:04",
"rank": 0,
"flow_id": "R2pfdn",
"timezone": null,
"settings": {},
"type": "SEND_MESSAGE",
"id": 17348418
}
]

I tried the other endpoint : api/v1/flow/FLOW_ID/action/17348418?api_key=pk_*******

and here is the result (the same actually)

{
"status": "live",
"delay_seconds": 0,
"created": "2020-11-24 09:52:32",
"send_time": "None",
"object": "flow-action",
"updated": "2021-01-27 09:07:04",
"rank": 0,
"flow_id": "R2pfdn",
"timezone": null,
"settings": {},
"type": "SEND_MESSAGE",
"id": 17348418
}

So at this point, it’s not possible using Klaviyo’s API, right ?

Once again, thanks for your time :grinning:

Thomas.

Userlevel 4
Badge +11

@Thomas_Rodier try this URL

 

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

Badge +2

Well thanks a lot @jallain !

 

Appreciate your help,

Take care,

Have a nice day!

 

Badge

Hi @jallain!

 

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\"."

}

Has this changed?  other suggestions?

Thanks in advance!

  • Team Cohley!
Badge

Amazing impact of POST vs. GET… got it working now!

Reply