Receive email alerts when inventory levels change with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Receive email alerts when inventory levels change

by Isaac Bowen (team@usemechanic.com)

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.

Runs when an inventory level is updated and when an inventory level is connected. Configuration includes email recipient, email subject, and email body.

15-day free trial – unlimited tasks

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.

Developer details

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

Events
when an inventory level is updated (shopify/inventory_levels/update)
when an inventory level is connected (shopify/inventory_levels/connect)
Options
email recipient (email, required), email subject (required), email body (required, multiline)
Script
{% 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 tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
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_level.variant.product_id }}/variants/{{ inventory_level.variant.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 }}