> For the complete documentation index, see [llms.txt](https://learn.mechanic.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.mechanic.dev/core/tasks.md).

# Tasks

Tasks are the building blocks of Shopify automation in Mechanic — Liquid code that responds to events and performs actions like tagging, emailing, and syncing data.

A task is an automation unit — it watches for something to happen in your store and responds with one or more actions. A task might tag every order over $100, send a notification when inventory is low, or sync customer data to a spreadsheet.

Under the hood, a **task** combines Liquid code with user-configurable [**options**](/core/tasks/options.md) and a set of event [**subscriptions**](/core/tasks/subscriptions.md). When an event matches a subscription, Mechanic executes the task's code with access to the event data. The code can query the Shopify Admin API, apply conditional logic, iterate over data, and render any number of [**actions**](/core/actions.md) — Shopify mutations, emails, HTTP requests, file generation, and more.

A task uses its [**preview**](/core/tasks/previews.md) 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**](/core/tasks/permissions.md) a task requires. Tasks can also declare their permissions explicitly using the [`{% permissions %}` tag](/platform/liquid/tags/permissions.md).

Tasks may be written from scratch, or installed from the Mechanic library (available in-app and [on GitHub](https://github.com/lightward/mechanic-tasks)). Once installed, a task's code may be modified at any time.

{% hint style="info" %}
Working on getting better at task-writing? See [Practicing writing tasks](/resources/tutorials/practicing-writing-tasks.md), and [Writing a high-quality task](/techniques/writing-a-high-quality-task.md).
{% endhint %}

For updates to tasks you've installed from the library, see [Updating library tasks](/resources/task-library/updating-tasks.md).

## Example

This very basic task subscribes to shopify/customers/create, and renders an [Email action](/core/actions/email.md), using an email subject and body taken from user-configured [options](/core/tasks/options.md).

**Subscriptions**

```
shopify/customers/create
```

**Code**

```liquid
{% 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**

```
{"name":"Customer signup alerts","options":{"email_recipient__email_required":"aesha@example.com","email_subject__required":"A new customer has signed up: {{ customer.email }}","email_body__multiline_required":"Hi! View this customer's details online:\n\nhttps://{{ shop.domain }}/admin/customers/{{ customer.id }}\n\n-Mechanic"},"script":"{% action \"email\" %}\n  {\n    \"to\": {{ options.email_recipient__email_required | json }},\n    \"subject\": {{ options.email_subject__required | json }},\n    \"body\": {{ options.email_body__multiline_required | newline_to_br | json }},\n    \"from_display_name\": {{ shop.name | json }}\n  }\n{% endaction %}","subscriptions":["shopify/customers/create"],"online_store_javascript":null,"order_status_javascript":null,"docs":null,"subscriptions_template":"shopify/customers/create","shopify_api_version":"2022-04","liquid_profiling":false,"perform_action_runs_in_sequence":false,"halt_action_run_sequence_on_error":false,"preview_event_definitions":[]}
```

![](https://3145272362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQrnkixbmVHvKHMwAbm%2Fuploads%2Fgit-blob-bb9de264ce857145a7dedbb0fa1ef55d08bb14c9%2FScreen%20Shot%202022-04-01%20at%207.14.46%20PM.png?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learn.mechanic.dev/core/tasks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
