Send an event to Klaviyo when a fulfillment is delayed, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Send an event to Klaviyo when a fulfillment is delayed

by Isaac Bowen (team@usemechanic.com)

This task will watch for new order fulfillments, waiting a configurable number of days after each one. When the waiting period is over, if the fulfillment's status matches an item in the list, this task will send an event to Klaviyo, allowing you to use Klaviyo to contact the customer appropriately.

Runs 5 days after an order is fulfilled. Configuration includes test mode, qualifying fulfillment statuses, klaviyo api token, klaviyo event name, and days to wait before checking.

15-day free trial – unlimited tasks

Documentation

This task will watch for new order fulfillments, waiting a configurable number of days after each one. When the waiting period is over, if the fulfillment's status matches an item in the list, this task will send an event to Klaviyo, allowing you to use Klaviyo to contact the customer appropriately.

Configure the "Qualifying fulfillment statuses" option with values from Shopify's "shipment_status" documentation.

Enable "Test mode" to make available a "Run task" button - press this button to have Mechanic send a test event to Klaviyo, allowing you to verify that everything's connected properly.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

Events
5 days after an order is fulfilled (shopify/orders/fulfilled+5.days)
Options
test mode (boolean), qualifying fulfillment statuses (array, required), klaviyo api token (required), klaviyo event name (required), days to wait before checking (number, required)
Script
{% if options.test_mode__boolean or event.preview %}
  {% capture order_json %}
    {
      "name": "#1234",
      "email": "customer@example.com",
      "fulfillments": [
        {
          "shipment_status": {{ options.qualifying_fulfillment_statuses__array_required[0] | json }}
        }
      ]
    }
  {% endcapture %}
  {% assign order = order_json | parse_json %}
{% else %}
  {% assign order = order.reload %}
{% endif %}

{% assign fulfillments_qualify = false %}

{% for fulfillment in order.fulfillments %}
  {% if options.qualifying_fulfillment_statuses__array_required contains fulfillment.shipment_status %}
    {% assign fulfillments_qualify = true %}
  {% endif %}
{% endfor %}

{% if fulfillments_qualify %}
  {% assign klaviyo_data = hash %}
  {% assign klaviyo_data["token"] = options.klaviyo_api_token__required %}
  {% assign klaviyo_data["event"] = options.klaviyo_event_name__required %}
  {% assign klaviyo_data["customer_properties"] = hash %}
  {% assign klaviyo_data["customer_properties"]["$email"] = order.email %}
  {% assign klaviyo_data["properties"] = hash %}
  {% assign klaviyo_data["properties"]["order_name"] = order.name %}

  {% action "http" %}
    {
      "method": "get",
      "url": "https://a.klaviyo.com/api/track?data={{ klaviyo_data | json | base64 }}"
    }
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Qualifying fulfillment statuses
["in_transit", "failure", "attempted_delivery"]
Klaviyo event name
Fulfillment delayed or failed
Days to wait before checking
5