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 API

Resourceful REST

Accepts an array of options, containing these elements in order:

  1. Operation
    Must be one of "create" , "update" , or "delete" .
  2. Resource specification
    When creating, use a single string (e.g. "customer" ).
    When updating or deleting, use an array (e.g. ["customer", 123] ).
  3. An object of attributes
    Only applies to creating and updating.

A task which tags a customer upon ordering might look like this:

{
  "action": {
    "type": "shopify",
    "options": [
      "update",
      [
        "customer",
        {{ order.customer.id }}
      ],
      {
        "tags": {{ order.customer.tags | add_tag: "ordered" | json }}
      }
    ]
  }
}

Explicit REST

Accepts an array of options, containing these elements in order:

  1. Operation
    Must be one of "post" , "put" , or "delete" 
  2. Request path
    Literally, the path you want to request from Shopify – the entire path. For example, /admin/orders.json .
  3. An object of attributes
    Same as the resourceful options style. :)

A task which tags a customer upon ordering might look like this:

{
  "action": {
    "type": "shopify",
    "options": [
      "put",
      "/admin/customers/{{ order.customer.id }}.json",
      {
        "tags": {{ order.customer.tags | add_tag: "ordered" | json }}
      }
    ]
  }
}

GraphQL

Accepts a simple string, containing the GraphQL query.

A task which tags a customer upon ordering might look like this:

{% assign customer = shop.customers[order.customer.id] %}

{% capture graphql_query %}
  mutation {
    tagsAdd(
      id: {{ customer.admin_graphql_api_id | json }}
      tags: "ordered"
    ) {
      userErrors {
        field
        message
      }
    }
  }
{% endcapture %}

{
  "action": {
    "type": "shopify",
    "options": {{ graphql_query | json }}
  }
}
Did this answer your question?