Mechanic
đŸ“Ŗ Shopify REST Deprecation
  • â›Šī¸Introduction
  • 🤓Hire a Mechanic developer
  • đŸ’¯status.mechanic.dev
  • đŸ“ŖShopify is deprecating the REST API
  • 🙋"I need something custom!"
  • 🧑‍đŸ’ģ"I need help with my custom task!"
  • 🤖"I need help with my AI-written task!"
  • Resources
    • âŦ‡ī¸Install Mechanic
    • 🧑‍đŸ’ģTask library
      • Contributing
      • Requesting
    • 🚀Slack community
    • 🤝Partner directory
    • 🧠Tutorials
      • Video walkthroughs
        • Auto-tag orders by originating staff member
        • Maintain a tag for orders processed today
        • Auto-tag orders with their tracking numbers
        • Sync inventory for shared SKUs
        • Auto-tag products when their SKU(s) change
        • Auto-publish new products
        • Email a report of customers who haven't ordered in X days
        • Upgrading a Mechanic task: Adding a time delay
        • Email the customer when tracking numbers are added to their order
        • Adding an optional time delay to your Mechanic task
        • Delete all orders
        • Send an email when a specific product is shipped
        • Send recurring reminders about unpaid orders
        • Send an email when a product's price goes below its cost
        • Auto-tag customers by sales channel
        • Creating products in bulk
      • Creating a Mechanic webhook
      • Practicing writing tasks
      • Triggering tasks from a contact form
      • Creating scheduled CSV feeds
      • Fetching data from a shared Google sheet
    • 🏆Converting tasks from Shopify REST to GraphQL
      • Conversion: Single resource lookups
      • Conversion: Resource loops to paginated queries
      • Conversion: Connections from a resource
      • Conversion: Metafield lookups from a resource
      • Conversion: Resource lookups in task option fields
  • Core Concepts
    • Events
      • Topics
      • Parent and child events
    • Tasks
      • Subscriptions
      • Code
        • Environment variables
        • Action objects
        • Error objects
        • Log objects
      • Options
        • Custom validation
      • Previews
        • Defining preview events
        • Stub data
      • Shopify API version
      • Advanced settings
        • Documentation
        • JavaScript
        • Perform action runs in sequence
      • Import and export
      • User Form
    • Actions
      • Cache
      • Echo
      • Email
      • Event
      • Files
      • Flow
      • FTP
      • Google Drive
      • Google Sheets
      • HTTP
      • Integrations
        • Report Toaster
      • Shopify
      • File generators
        • Base64
        • PDF
        • Plaintext
        • URL
        • ZIP
    • Runs
      • Scheduling
      • Concurrency
      • Ordering
      • Retries
    • Interacting with Shopify
      • Responding to events
        • Reconciling missing events
      • Reading data
        • âš ī¸Liquid objects
        • 🏆GraphQL in Liquid
        • Bulk operations
        • The Shopify action
      • Writing data
      • Shopify admin action links
      • API rate limit
      • API versions
  • Platform
    • 🔆Policies
      • Data
      • Plans
      • Pricing
      • Privacy
    • Cache
      • Cache endpoints
    • Email
      • Receiving email
      • Custom email addresses
      • DMARC
      • Email templates
    • Error handling
    • Events
      • Event topics
      • Event filters
    • GraphQL
      • Basics
        • Shopify Admin API GraphiQL explorer
        • Queries
        • Mutations
        • Pagination
      • Bulk operations
    • Integrations
      • Appstle Subscriptions
      • Google Drive and Google Sheets
      • Judge.me
      • Locksmith
      • Report Toaster
      • Shopify Flow
      • Run links
    • Liquid
      • Basics
        • Syntax
        • Data types
        • Variables
        • Comments
        • Filters
        • Operators
        • Control flow
          • Condition
          • Iteration
        • Whitespace
      • Liquid console
      • Mechanic filters
        • Deprecated filters
      • Mechanic keyword literals
        • array
        • hash
        • newline
      • Mechanic objects
        • Action object
        • Cache object
        • Event object
        • Options object
        • Task object
        • âš ī¸Shopify REST Admin API
          • đŸšĢArticle object
          • đŸšĢBlog object
          • đŸšĢCollection object
          • đŸšĢCustomer object
          • đŸšĢDiscount code object
          • đŸšĢDispute object
          • đŸšĢDraft order object
          • đŸšĢFulfillment object
          • đŸšĢFulfillment order object
          • đŸšĢFulfillment event object
          • đŸšĢGift card object
          • đŸšĢInventory item object
          • đŸšĢInventory level object
          • đŸšĢLine item object
          • đŸšĢLocation object
          • đŸšĢMetafields
            • Metafield object
            • Metafield representation object
            • Metafield collection object
          • đŸšĢOrder object
          • đŸšĢOrder risk object
          • đŸšĢPrice rule object
          • đŸšĢProduct object
          • đŸšĢProduct image object
          • đŸšĢRefund object
          • đŸšĢShipping zone object
          • đŸšĢShop object
          • đŸšĢTheme object
          • đŸšĢTheme asset object
          • đŸšĢTransaction object
          • đŸšĢVariant object
      • Mechanic tags
        • liquid
        • action
        • assign
        • error
        • log
      • Mechanic code snippets
    • Shopify
      • Custom authentication
      • "Read all orders"
    • Webhooks
  • Techniques
    • Preventing action loops
    • Writing a high-quality task
    • Tagging Shopify resources
    • Debouncing events
    • Responding to action results
    • Working with external APIs
      • JSON Web Signatures
      • AWS request signatures
    • Finding a resource ID
    • Migrating templates from Shopify to Mechanic
    • Securing Mechanic webhooks
    • Monitoring Mechanic
  • FAQ
    • The app isn't loading. What do I do?
    • How do I stop a large batch of runs?
    • A Shopify event is missing. Where is it?
    • Does Mechanic have an affiliate program?
    • Can non-owners install Mechanic?
    • Can I replace Shopify's order emails with Mechanic?
    • Can I manually set Shopify permissions for Mechanic?
    • Does my theme need to be updated for Mechanic?
    • Do you have a plan for development stores?
    • Why don't I see any events in my task's activity?
    • Can I read data back from my webhook submission?
    • My task added a tag, but now the tag is missing – why?
    • How do I add an unsubscribe link to my emails?
    • How do I send images with my emails?
    • Can I re-send order confirmation emails with Mechanic?
    • Why am I seeing a different price than on the app store?
    • Do you have a Partner-friendly plan?
    • Why are my tasks delayed or not running?
    • My task is failing because of a permissions problem. Why?
    • How do I preview email attachments?
    • Can I query external APIs?
    • Why can't I access the Shopify API during preview mode?
    • How do marketing preferences work with Mechanic?
    • Can I send data to Google Sheets?
    • What's possible with timeline comments?
    • I'm getting a "query param length is too long" error when using GraphQL.
    • Can my Mechanic concurrency limit be raised?
    • What IP address does Mechanic use?
    • Can Mechanic read or manage customer subscriptions?
    • Why is everything harder now?
    • Can task content be translated into multiple languages?
    • Can I add a time delay to my task?
    • Can I add another store to my existing Mechanic subscription?
    • How can I reduce memory usage of my task?
    • How do I connect PayPal to Shopify with Mechanic?
    • How do I add a Shopify access scope to my task?
    • Can I have my Mechanic data retained for more (or less) than 15 days?
Powered by GitBook

Important Updates

  • đŸ“Ŗ Shopify REST Deprecation
On this page
  • Task code
  • Generating a PDF with a template from task options
  • Generating email body HTML using a template from task options
  • Generating email body HTML from a reusable email template
  • Preparing the template
  • Update variables to reference order properties
  • Check for Liquid filter support
  • Convert numeric strings to numbers, and check on money rendering
  • Check your stylesheets
  • Updating branding

Was this helpful?

Edit on GitHub
Export as PDF
  1. Techniques

Migrating templates from Shopify to Mechanic

PreviousFinding a resource IDNextSecuring Mechanic webhooks

Last updated 1 year ago

Was this helpful?

Shopify notification templates can be manually migrated over to Mechanic in order to generate order-related material on-demand in Mechanic. This could look like , or .

Common sources for these templates include Shopify's email notification settings, Shopify's app, and .

We'll talk about this in two parts: the task code, and then the steps required for preparing a Shopify template for use with Mechanic.

Before we begin, note that there are two ways to think about templates:

  • Reusable email templates, as we'll call them here, are configured in Mechanic's "Email templates" settings area. Here, email templates may be keyed with a name and saved for later use and reuse by any number of tasks.

  • Task-level templates are ad-hoc pieces of Liquid code, informally defined within an individual task, and possibly made user-configurable via . While this page focuses on using templates for email purposes, a task-level template may be used for more than just emails: a task might also use these to generate PDFs, or file content to save via FTP, or (in very advanced cases) even entire .

Task code

There are several ways your task code might be set up for exercising a template.

In any of these scenarios, your Shopify template will need to be modified before it'll function as intended in Mechanic, and we'll talk about that below in .

Generating a PDF with a template from task options

To generate an order PDF to send as an email, you might use a task like this one, paired with a subscription to shopify/orders/create. Note how the template is made user-configurable by a task option, implicitly created by the options.pdf_html_template__code_multiline_required variable reference.

{% action "email" %}
  {
    "to": {{ order.email | json }},
    "subject": {{ options.email_subject__required | strip | json }},
    "body": {{ options.email_body__multiline_required | strip | newline_to_br | json }},
    "reply_to": {{ shop.customer_email | json }},
    "from_display_name": {{ shop.name | json }},
    "attachments": {
      {{ options.pdf_attachment_filename__required | json }}: {
        "pdf": {
          "html": {{ options.pdf_html_template__code_multiline_required | json }}
        }
      }
    }
  }
{% endaction %}

Generating email body HTML using a template from task options

To send out an order-related email where all the details are provided as HTML in the email itself, you might use something like this. Note how, as above, the template is set using task options.

{% action "email" %}
  {
    "to": {{ order.email | json }},
    "subject": {{ options.email_subject__required | json }},
    "body": {{ options.email_body_html__required_multiline_code | strip | json }},
    "reply_to": {{ shop.customer_email | json }},
    "from_display_name": {{ shop.name | json }}
  }
{% endaction %}

Generating email body HTML from a reusable email template

You may pass along additional variables to your email template, by using your own custom action options. In the example below, we pass along two custom options, with two different techniques:

  • By specifying "order_data", we allow the email template to use a variable called order_data which includes a copy of everything we know about the current order. The email template will be able to call values from this variable using something like {{ order_data.name }}.

  • By specifying "additional_data", we define our own static values for a new email template variable called additional_data. The order template will be able to call values from this variable using something like {{ additional_data.some }}.

{% action "email" %}
  {
    "to": {{ order.email | json }},
    "subject": {{ options.email_subject__required | json }},
    "reply_to": {{ shop.customer_email | json }},
    "from_display_name": {{ shop.name | json }},
    "template": "some_template_name",
    "order_data": {{ order | json }},
    "additional_data": {
      "some": "additional values"
    }
  }
{% endaction %}

Preparing the template

Shopify and Mechanic both use Liquid code for their templates. Run through the following changes to convert your Shopify templates (whether from a Shopify email notification or from the Order Printer app) to something Mechanic can use.

Update variables to reference order properties

Rather than changing all of these variable references across the template, it may be easier to initialize those variables at the top of the template code, using something like this:

{% assign total_price = order.total_price %}
{% assign transactions = order.transactions %}
{% assign email = order.email %}

Some variables from Shopify are already given as properties of an object you can use in Mechanic. For example, {{ shop.name }} works in both Order Printer and in Shopify.

Check for Liquid filter support

Mechanic Liquid supports many filters from Shopify Liquid, but not all of them! If a filter isn't working the way you expect, check Mechanic's list of supported Shopify Liquid filters. You may need to adjust your code to work around filters that Mechanic Liquid doesn't support.

Convert numeric strings to numbers, and check on money rendering

This is particularly important if the figure is used in a logical condition, like this one:

{% if order.total_price > 5000 %}

Because order.total_price is a string, and because Liquid filters cannot be used in the middle of an if or unless tag, one should first assign the numeric value to a new variable and then update the condition to use that new variable.

{% assign total_price_number = order.total_price | times: 1 %}
{% if total_price > 5000 %}

For numbers that are formatted with the "money" or "money_with_currency" filter, check to make sure that the final numbers are correct. You may need to multiply the number by 100 to achieve the expected results, as in:

{{ order.total_price | times: 100 | money }}
{{ order.total_price | times: 100 | money_with_currency }}

Check your stylesheets

There is one exception scenario. When using email templates, Mechanic will automatically replace this tag:

<link rel="stylesheet" type="text/css" href="/assets/notifications/styles.css">

... with a style tag containing rules extracted from Shopify's default notification emails. You may still need to make overriding changes, particularly for brand colors, but this should help you make progress more rapidly.

Note: This <link> tag substitution only happens for reusable email templates. It does not occur in ad-hoc templates defined at the task level, or anywhere else.

Updating branding

To bring over your email colors, go back to the "Notifications" area in Shopify, and click on the "Customize" button, under "Customer notifications". You'll see a setting for "Accent color". Click on the block of color, then copy the string of text that looks like "#ABCDEF". This is your color accent code. :) Back in your Mechanic email template, replace the two instances of "#1990c6" (the default accent color) with the color code that you copied, then save your settings.

To send an email using a reusable , as configured in your Mechanic settings, use the "template" option of the .

To learn more about this, see .

Shopify uses variables like {{ total_price }} and {{ transactions }} and {{ email }}. These variables aren't automatically available in Mechanic, but the right pieces of data all available via , using references like {{ order.total_price }} and {{ order.transactions }} and {{ order.email }}.

To see what variables Shopify uses in their notification templates, . If you're using Order Printer, you can find a similar list by opening up a template in the app, and clicking the "View the Liquid variable list" link.

Mechanic's usual sources for querying Shopify data may be used here as well. To learn more about pulling in Shopify data, see .

Mechanic uses API data from Shopify to power . Because the Shopify API makes money figures available as strings, one may need to cast these values to numbers for parts of your template to work correctly. This may be done via assignment, as in {% assign foo = some_number | times: 1 %}, or at the time of output, as in {{ some_number | times: 1 }}.

External stylesheets are not supported for emails (though they are supported for the ). This means that, for email content, any <link rel="stylesheet"> tags need to be replaced with a <style> tag, containing the full contents of that stylesheet.

To bring over your shop's logo, see our guide – see the "Embedding images" section.

email template
Email action
the Order object
see their documentation
Reading data
the Order object
PDF file generator
How do I send images with my emails?
triggering an order confirmation email
generating a PDF invoice
Order Printer
OrderlyEmails
task options
action objects
Preparing the template
Creating email template variables