Anything that Shopify allows developers to do, Mechanic lets you automate. This means that you can create, update, or delete nearly anything in your Shopify account.
Here are some ideas:
- Tagging customers
- Creating a draft order for every customer who signs up
- Emailing your staff when an order is delivered
Mechanic has a few built-in tasks that take advantage of this action, but the possibilities are literally limitless. Work with a developer or hit that chat button in the corner to explore your options. :)
For developers
The "shopify" action has three styles of usage:
- Resourceful REST, which uses Shopify's REST admin API in a style reminiscent of ActiveResource
- Explicit REST, which uses Shopify's REST admin API with explicitly defined values for HTTP method, url, and body
- GraphQL, which uses Shopify's GraphQL admin API
Use resourceful REST if it's easy to do so – its job is to keep simple things simple. Use explicit REST if you need to get really specific about how your API request works. Use GraphQL when you need a feature not available in the REST API, or if it's otherwise more convenient/natural to do so.
Tip: if you're working with tags, always use GraphQL, to avoid accidentally overwriting tags added or removed by a simultaneously-running task. Learn more about tagging
Resourceful REST
Accepts an array of options, containing these elements in order:
-
Operation
Must be one of"create"
,"update"
, or"delete"
. -
Resource specification
When creating, use a single string (e.g."customer"
).
When updating or deleting, use an array (e.g.["customer", 123]
). -
An object of attributes
Only applies to creating and updating.
A task which tags a customer upon ordering might look like this:
{% action "shopify" %}
[
"update",
[
"customer",
{{ order.customer.id | json }}
],
{
"tags": {{ order.customer.tags | add_tag: "ordered" | json }}
}
]
{% endaction %}
Explicit REST
Accepts an array of options, containing these elements in order:
-
Operation
Must be one of"post"
,"put"
, or"delete"
-
Request path
Literally, the path you want to request from Shopify – the entire path. For example,/admin/orders.json
. -
An object of attributes
Same as the resourceful options style. :)
A task which tags a customer upon ordering might look like this:
{% action "shopify" %}
[
"put",
"/admin/customers/{{ order.customer.id }}.json",
{
"tags": {{ order.customer.tags | add_tag: "ordered" | json }}
}
]
{% endaction %}
GraphQL
Accepts a valid GraphQL query.
A task which tags a customer upon ordering might look like this:
{% assign customer = shop.customers[order.customer.id] %}
{% action "shopify" %}
mutation {
tagsAdd(
id: {{ customer.admin_graphql_api_id | json }}
tags: "ordered"
) {
userErrors {
field
message
}
}
}
{% endaction %}