Mechanic Get Mechanic
Task library

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.

Try this task

When it runs

Occurs whenever a fulfillment is created

What you choose

  • Tracking number prefix to add
  • Notify customer
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/fulfillments/create
How task subscriptions work

Option types and flags

Task 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 %}
Mechanic Liquid reference

Default option values

Notify customer
false