Mechanic Get Mechanic
Task library

Auto-tag new orders with product SKUs

This task watches for new orders, and tags each order with all line item SKUs found in that order.

Try this task

When it runs

Occurs whenever an order is created

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

Subscriptions

shopify/orders/create
How task subscriptions work

Task code

{% if event.preview %}
  {% capture order_json %}
    {
      "admin_graphql_api_id": "gid://shopify/Order/12345",
      "line_items": [
        {
          "sku": "ABC123"
        },
        {
          "sku": null
        },
        {
          "sku": "DEF456"
        }
      ]
    }
  {% endcapture %}

  {% assign order = order_json | parse_json %}
{% endif %}

{% assign skus = order.line_items | map: "sku" | compact %}

{% if skus != empty %}
  {% action "shopify" %}
    mutation {
      tagsAdd(
        id: {{ order.admin_graphql_api_id | json }}
        tags: {{ skus | json }}
      ) {
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}
Mechanic Liquid reference