githubEdit

Tasks

Tasks are automation rules that respond to Shopify events and perform actions like tagging, emailing, and syncing data.

A task is an automation rule β€” it watches for something to happen in your store and responds automatically. For example, a task might tag every order over $100, send a notification when inventory is low, or sync customer data to a spreadsheet.

Technically, a task is a bundle of logic and configuration, that responds to and interprets events. The result of a task can define actions, which are the task's opportunities to have an effect on the world.

A task responds to events based on its subscriptions. When an event is received that matches a subscription, the task processes the event using its code. The code has access to the event data; it also has access to the user's task configuration, through options. Task code is written in Liquid, and is responsible for rendering a series of JSON objects (including action, error, and log objects), defining work to be performed once task rendering is complete.

A task uses its preview to communicate ahead of time the work it intends to do. Previews are important for users, and are also important for Mechanic itself – Mechanic looks to the task preview to understand what permissions a task requires. Tasks can also declare their permissions explicitly using the {% permissions %} tag.

Tasks may be written from scratch, or installed from the Mechanic library (available in-app and on GitHubarrow-up-right). Once installed, a task's code may be modified at any time.

circle-info

Working on getting better at task-writing? See Practicing writing tasks, and Writing a high-quality task.

Example

This very basic task subscribes to shopify/customers/create, and renders an Email action, using an email subject and body taken from user-configured options.

Subscriptions

shopify/customers/create

Code

{% action "email" %}
  {
    "to": {{ options.email_recipient__email_required | json }},
    "subject": {{ options.email_subject__required | json }},
    "body": {{ options.email_body__multiline_required | newline_to_br | json }},
    "from_display_name": {{ shop.name | json }}
  }
{% endaction %}

Export

Last updated

Was this helpful?