Demonstration: Shopify Flow integration, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Demonstration: Shopify Flow integration

This task demonstrates how to use the four Mechanic Shopify Flow triggers: General, Customer, Product, and Order.

Runs Occurs when a user manually triggers the task, Occurs whenever user/flow/customer is triggered, Occurs whenever user/flow/order is triggered, Occurs whenever user/flow/product is triggered, and Occurs whenever user/flow/general is triggered. Configuration includes customer id, order id, product id, and send general trigger.

15-day free trial – unlimited tasks

Documentation

This task demonstrates how to use the four Mechanic Shopify Flow triggers: General, Customer, Product, and Order.

You'll learn about the user-defined data that we can send to Shopify Flow: user_boolean, user_email, user_number, user_string, user_url.

We demonstrate subscribing to an event topic fired by a Shopify Flow action. You'll need to set up a workflow in the Shopify Flow app to trigger this event topic. This example could be in any Mechanic task; we have this as part of this task for demonstration purposes. The event topic can be anything in the user domain. We choose user/flow/customer (etc), but it could be something like user/flow/xyz.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, 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.

(By the way, have you seen our documentation? Have you joined the Slack community?)

Open source
View on GitHub to contribute to this task
Subscriptions
mechanic/user/trigger

user/flow/customer
user/flow/order
user/flow/product
user/flow/general
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
customer id (number), order id (number), product id (number), send general trigger (boolean)
Code
{% comment %}
  In this example we show how to use all four Shopify Flow tiggers:
  1. General
  2. Customer
  3. Order
  4. Product
{% endcomment %}

{% assign customer_id = options.customer_id__number %}
{% assign order_id = options.order_id__number %}
{% assign product_id = options.product_id__number %}

{% if event.topic == "mechanic/user/trigger" %}
  {% comment %}
    Testing the Customer trigger for Flow
  {% endcomment %}

  {% if customer_id %}
    {% action "flow" %}
      {
        "customer_id": {{ customer_id }},

        "user_number":  55,
        "user_string":  "Love!"
      }
    {% endaction %}
  {% endif %}

  {% if order_id %}
    {% comment %}
      Testing the Order trigger for Flow
    {% endcomment %}

    {% action "flow" %}
      {
        "order_id": {{ order_id }},

        "user_number":  55,
        "user_string":  "Love!"
      }
    {% endaction %}
  {% endif %}

  {% if product_id %}
    {% comment %}
      Testing the Product trigger for Flow
    {% endcomment %}

    {% action "flow" %}
      {
        "product_id": {{ product_id }},

        "user_number":  55,
        "user_string":  "Love!"
      }
    {% endaction %}
  {% endif %}

  {% if options.send_general_trigger__boolean %}
    {% comment %}
      Testing the General trigger for Flow
    {% endcomment %}

    {% action "flow" %}
      {
        {% comment %}
          Keep as many of the following as you like. Any omitted
          keys *will* be submitted anyway, using the default value
          given below. If you don't want to use Mechanic's default
          value, make sure to *keep* the key in place below, setting
          it to whatever you like.
        {% endcomment %}
        "user_boolean": false,
        "user_email":   "hey@mechanic.invalid",
        "user_number":  0,
        "user_string":  "",
        "user_url":     "https://mechanic.invalid/"
       }
    {% endaction %}
  {% endif %}
{% endif %}

{% comment %}
  Next, we show triggering a Mechanic task from a Flow action.

  A few quick points:
   - This could be in any Mechanic task. we have this example as part
     of this task for demonstration purposes.
   - To exercise this part of the task, you'll need to set up a Shopify
     Flow to send an action to this event topic.
   - The event topic can be anything in the user domain. We use topics
     starting with "user/flow/", but it could be something like
     "user/foo/bar" too.

  To quickly test echoing data from Mechanic *back* to Mechanic, add a
  Mechanic action to your Flow workflow configured with the following
  event data value:

  {
    "user_boolean": {{ userBoolean | json }},
    "user_email": {{ userEmail | json }},
    "user_number": {{ userNumber | json }},
    "user_string": {{ userString | json }},
    "user_url": {{ userUrl | json }},
    "mechanic_event_topic": {{ mechanicEventTopic | json }},
    "mechanic_task_id": {{ mechanicTaskId | json }},
    "mechanic_event_inspector_url": {{ mechanicEventInspectorUrl | json }}
  }
{% endcomment %}

{% if event.topic contains "user/flow/" %}
  {% log flow_event_data: event.data %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more
Defaults
Send general trigger
true