Auto-prefix tracking numbers for each new fulfillment, with Mechanic.

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

Auto-prefix tracking numbers for each new fulfillment

This task runs immediately after each new fulfillment is created, and adds a prefix to its tracking number, if a tracking number is present.

Runs Occurs whenever a fulfillment is created. Configuration includes tracking number prefix to add and notify customer.

15-day free trial – unlimited tasks

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
shopify/fulfillments/create
Tasks use subscriptions to sign up for specific kinds of events. Learn more
Options
tracking number prefix to add (required), notify customer (boolean)
Code
{% if event.preview %}
  {% assign fulfillment = hash %}
  {% assign fulfillment["tracking_number"] = "1234567890" %}
  {% assign fulfillment["admin_graphql_api_id"] = "gid://shopify/Fulfillment/1234567890" %}
{% endif %}

{% if fulfillment.tracking_number == blank %}
  {"log": "This fullfilment has no tracking number; can't add a prefix"}
{% else %}
  {% action "shopify" %}
    mutation {
      fulfillmentTrackingInfoUpdate(
        fulfillmentId: {{ fulfillment.admin_graphql_api_id | json }}
        trackingInfoUpdateInput: {
          trackingDetails: {
            number: {{ fulfillment.tracking_number | prepend: options.tracking_number_prefix_to_add__required | json }}
          }
          notifyCustomer: {{ options.notify_customer__boolean | json }}
        }
      ) {
        fulfillment {
          trackingInfo {
            number
          }
        }
        userErrors {
          field
          message
        }
      }
    }
  {% endaction %}
{% endif %}
Task code is written in Mechanic Liquid, an extension of open-source Liquid enhanced for automation. Learn more