Receive email alerts when inventory levels change
Use this task to receive immediate email notifications whenever inventory/stock levels are adjusted, whether manually or as a result of a transfer or customer order.
Try this taskWhen it runs
- Occurs whenever an inventory level is updated
- Occurs whenever an inventory level is connected
What you choose
- Email recipient
- Email subject
- Email body
Documentation
Use this task to receive immediate email notifications whenever inventory/stock levels are adjusted, whether manually or as a result of a transfer or customer order.
Please note: Mechanic will start sending emails the second time inventory is adjusted for a particular item.
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/inventory_levels/update
shopify/inventory_levels/connect
How task subscriptions work
Option types and flags
- Email recipient (email, required)
- Email subject (required)
- Email body (required, multiline)
Task code
{% if event.preview %}
{% capture inventory_level_json %}
{
"inventory_item_id": 271878346596884015,
"location_id": 48752903,
"available": 5
}
{% endcapture %}
{% assign inventory_level = inventory_level_json | parse_json %}
{% endif %}
{% assign cache_key = "inventory_level:" | append: inventory_level.inventory_item_id | append: "/" | append: inventory_level.location_id %}
{% assign previous_available = cache[cache_key] %}
{% if previous_available != nil %}
{% assign available_difference = inventory_level.available | minus: previous_available %}
{% if available_difference >= 0 %}
{% assign available_difference = "+" | append: available_difference %}
{% endif %}
{% action "email" %}
{
"to": {{ options.email_recipient__email_required | json }},
"subject": {{ options.email_subject__required | replace: "AVAILABLE", inventory_level.available | replace: "DIFFERENCE", available_difference | strip | json }},
"body": {{ options.email_body__required_multiline | replace: "AVAILABLE", inventory_level.available | replace: "DIFFERENCE", available_difference | strip | newline_to_br | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}
{% action "cache" %}
{
"set": {
"key": {{ cache_key | json }},
"value": {{ inventory_level.available }}
}
}
{% endaction %}
Mechanic Liquid reference
Default option values
- Email subject
DIFFERENCE inventory for {{ inventory_level.variant.sku }} {{ inventory_level.variant.product.title | default: "(Product title)" }} {% if inventory_level.variant.title != blank and inventory_level.variant.title != "Default Title" %}({{ inventory_level.variant.title }}) {% endif %}- Email body
Currently available inventory: AVAILABLE Changed by: DIFFERENCE Location: {{ inventory_level.location.name | default: "(location)" }} <a href="https://{{ shop.domain }}/admin/products/inventory/{{inventory_level.inventory_item_id}}/inventory_history?location_id={{ inventory_level.location_id }}">View inventory history</a> <a href="https://{{ shop.domain }}/admin/products/{{ inventory_level.variant.product_id }}/variants/{{ inventory_level.variant.id }}">Manage this variant</a> Thanks, {{ shop.name }}