Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
We're trying to set up a Shopify Flow which identifies failed deliveries and passes on the courier's unique tracking number (along with the customer email and order name) to Klaviyo as Event Properties (see also Klaviyo's docs).
The trigger of the Flow is a Scheduled Run combined with a Get Order Data action after which we run a 'For Each' loop on all the orders to send them to Klaviyo.
So far we got the customer email and orderNumber working by passing this to Klaviyo as follows:
{
"deliveryStatus": "deliveryFailed",
"customerEmail": "{{getOrderDataForeachitem.email}}",
"orderNumber": "{{getOrderDataForeachitem.name}}"
}
As for the tracking number, we are able to produce this via the following loop:
{% for fulfillmentOrders_item in getOrderDataForeachitem.fulfillmentOrders %}
{% for fulfillments_item in fulfillmentOrders_item.fulfillments %}
{% for trackingInfo_item in fulfillments_item.trackingInfo %}
{{trackingInfo_item.number}}
{% endfor %}
{% endfor %}
{% endfor %}
However, this in theory produces a list of tracking numbers whereas we only need a single tracking code value as we'll never have more than one tracking number assigned to an order. How can we condense the above loop in a single line statement that can be passed on as an Event Property to Klaviyo?
Solved! Go to the solution
This is an accepted solution.
Hi Monnedepraetere,
If it will always be the first item of each array, you could use the `| first` filter and `assign` to ensure you only get one value.
Something like:
{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}
{{ firstTrackingInfo.number }}
If you use ParcelPanel to connect Klaviyo via API, you can accomplish more than passing the tracking number, but also updating your customers on the latest shipment status. For example, after the shipment status is changed to "Delivered," it will be the best time to send a review request email.
Here's our help center article that might be helpful to you. How to connect ParcelPanel & Klaviyo via API?
Your loop seems correct (check if there's your needed data sent), once you have this create a new "then" event in Flow. That is HTTP Request to Klaviyo API to send only the current transaction. I'll follow the post.
Basic tutorial of API in Shopify Flow:
https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request
This is an accepted solution.
Hi Monnedepraetere,
If it will always be the first item of each array, you could use the `| first` filter and `assign` to ensure you only get one value.
Something like:
{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}
{{ firstTrackingInfo.number }}
Many thanks Dave, that worked.!
FYI - this is how the whole 'Event Properties' code section looks like in the end:
{% assign firstFulfillmentOrder = getOrderDataForeachitem.fulfillmentOrders | first %}
{% assign firstFulfillment = firstFulfillmentOrder.fulfillments | first %}
{% assign firstTrackingInfo = firstFulfillment.trackingInfo | first %}
{
"deliveryStatus": "deliveryFailed",
"customerEmail": "{{getOrderDataForeachitem.email}}",
"orderNumber": "{{getOrderDataForeachitem.name}}",
"trackingNumber": "{{ firstTrackingInfo.number }}",
"trackingUrl": "{{ firstTrackingInfo.url}}"
}
Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024Note: Customizing your CSS requires some familiarity with CSS and HTML. Before you cust...
By JasonH Aug 12, 2024