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
  • Options
  • GraphQL
  • GraphQL with variables
  • Resourceful REST
  • Explicit REST

Was this helpful?

Edit on GitHub
Export as PDF
  1. Core Concepts
  2. Actions

Shopify

PreviousReport ToasterNextFile generators

Last updated 7 months ago

Was this helpful?

The Shopify action sends requests to the . It supports both REST and GraphQL requests.

Important Notice

Shopify is deprecating the Shopify Admin REST API which the Mechanic REST objects depend on. The first round of deprecations involve the product and variant endpoints. Read about the deprecation and . Use the going forward. The and objects will cease to work on on Feb 1, 2025 due to the changes being made by Shopify. Shopify will phase out the REST API completely over time, you can read more about this .

All of our will be ported to use GraphQL only, which will provide a model for how you can update your custom tasks. You'll be able to update your non-customized library tasks with a click of a button Please see these for migrating your custom tasks to GraphQL.

In Mechanic, writing data to Shopify must happen using an action. While the Shopify action is usually the right choice, the action can also be used for this purpose, by manually configuring authentication headers.

To learn more, see .

Options

This action has several usage styles, each with a different set of constraints on action options.

GraphQL

This usage style invokes the . In this style, a single GraphQL query string is supplied as the action options. The tag has specific support for this action type, allowing this string to be provided as the contents of an action block.

To prepare complex query inputs, use the Liquid filter.

{% action "shopify" %}
  mutation {
    customerCreate(
      input: {
        email: "test@example.com"
      }
    ) {
      customer {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": "\n  mutation {\n    customerCreate(\n      input: {\n        email: \"test@example.com\"\n      }\n    ) {\n      customer {\n        id\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }\n"
  }
}

GraphQL with variables

Option

Description

query

Required; a string containing a GraphQL query

variables

Required; a JSON object mapping variable names to values

Basic example

{% capture query %}
  mutation DeleteProduct($productId: ID!) {
    productDelete(
      input: {
        id: $productId
      }
    ) {
      userErrors {
        field
        message
      }
    }
  }
{% endcapture %}

{% action "shopify" %}
  {
    "query": {{ query | json }},
    "variables": {
      "productId": "gid://shopify/Product/1234567890"
    }
  }
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": {
      "query": "\n  mutation DeleteProduct($productId: ID!) {\n    productDelete(\n      input: {\n        id: $productId\n      }\n    ) {\n      userErrors {\n        field\n        message\n      }\n    }\n  }\n",
      "variables": {
        "productId": "gid://shopify/Product/1234567890"
      }
    }
  }
}

Complex example

This example shows how the query and variables may be built up separately, and provided to the action using concise tag syntax.

{% assign metafield_owner_id = "gid://shopify/Customer/507332001849" %}
{% assign metafield_value = hash %}
{% assign metafield_value["foo"] = "bar" %}

{% capture query %}
  mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
    metafieldsSet(metafields: $metafields) {
      metafields {
        key
        namespace
        value
        createdAt
        updatedAt
      }
      userErrors {
        field
        message
        code
      }
    }
  }
{% endcapture %}

{% assign metafield = hash %}
{% assign metafield["ownerId"] = metafield_owner_id %}
{% assign metafield["namespace"] = "demo" %}
{% assign metafield["key"] = "demo" %}
{% assign metafield["type"] = "json" %}
{% assign metafield["value"] = metafield_value | json %}
{% assign metafields = array %}
{% assign metafields = metafields | push: metafield %}

{% assign variables = hash %}
{% assign variables["metafields"] = metafields %}

{% action "shopify" query: query, variables: variables %}
{
  "action": {
    "type": "shopify",
    "options": {
      "query": "\n  mutation SetCustomerMetafield(\n    $customerId: ID!\n    $metafieldNamespace: String!\n    $metafieldKey: String!\n    $metafieldId: ID\n    $metafieldValue: String!\n  ) {\n    customerUpdate(\n      input: {\n        id: $customerId\n        metafields: [\n          {\n            id: $metafieldId\n            namespace: $metafieldNamespace\n            key: $metafieldKey\n            valueType: STRING\n            value: $metafieldValue\n          }\n        ]\n      }\n    ) {\n      userErrors {\n        field\n        message\n      }\n      customer {\n        metafield(\n          namespace: $metafieldNamespace\n          key: $metafieldKey\n        ){\n          id\n        }\n      }\n    }\n  }\n",
      "variables": {
        "customerId": "gid://shopify/Customer/700837494845",
        "metafieldNamespace": "test",
        "metafieldKey": "test",
        "metafieldId": "gid://shopify/Metafield/18788961353789",
        "metafieldValue": "1615244317"
      }
    }
  }
}

Important Notice

  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.

Example: Creating a resource

This example creates a (minimal) customer record.

{% action "shopify" %}
  [
    "create",
    "customer",
    {
      "email": "test@example.com"
    }
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "create",
      "customer",
      {
        "email": "test@example.com"
      }
    ]
  }
}

Example: Updating a resource

This example appends a line to the order note (assuming a task subscription to shopify/orders/create).

{% action "shopify" %}
  [
    "update",
    [
      "order",
      {{ order.id | json }}
    ],
    {
      "note": {{ order.note | append: newline | append: newline | append: "We're adding a note! πŸ’ͺ" | strip | json }}
    }
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "update",
      [
        "order",
        3656038711357
      ],
      {
        "note": "[customer-supplied note]\n\nWe're adding a note! πŸ’ͺ"
      }
    ]
  }
}

Example: Deleting a resource

This example deletes a product, having a certain ID.

{% action "shopify" %}
  [
    "delete",
    ["product", 4814813560893]
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "delete",
      [
        "product",
        4814813560893
      ]
    ]
  }
}

Important Notice

  1. Operation Must be one of "get", "post" , "put" , or "delete"

When switching from resourceful to explicit REST, it's common to forget the outer wrapper object. This wrapper is required by Shopify for all request methods except GET and DELETE; it's handled automatically during resourceful usage, but must be handled manually during explicit usage.

Example: Creating a resource

This example creates a (minimal) customer record.

{% action "shopify" %}
  [
    "post",
    "/admin/api/2020-01/customers.json",
    {
      "customer": {
        "email": "test@example.com"
      }
    }
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "post",
      "/admin/api/2020-01/customers.json",
      {
        "customer": {
          "email": "test@example.com"
        }
      }
    ]
  }
}

Example: Updating a resource

This example appends a line to the order note (assuming a task subscription to shopify/orders/create).

{% action "shopify" %}
  [
    "put",
    "/admin/api/2020-01/orders/{{ order.id }}.json",
    {
      "order": {
        "note": {{ order.note | append: newline | append: newline | append: "We're adding a note! πŸ’ͺ" | strip | json }}
      }
    }
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "put",
      "/admin/api/2020-01/orders/3656063189053.json",
      {
        "order": {
          "note": "We're adding a note! πŸ’ͺ"
        }
      }
    ]
  }
}

Example: Deleting a resource

This example deletes a product, having a certain ID.

{% action "shopify" %}
  [
    "delete",
    "/admin/api/2020-01/products/4814813724733.json"
  ]
{% endaction %}
{
  "action": {
    "type": "shopify",
    "options": [
      "delete",
      "/admin/api/2020-01/products/4814813724733.json"
    ]
  }
}

This usage style invokes the , and supports combining GraphQL queries with . This can be useful for re-using queries with multiple inputs, and is critical when dealing with very large pieces of input. Because GraphQL queries (excluding whitespace) are limited in length to 50k characters, GraphQL variables can be used in cases when large inputs (like Base64-encoded images) need to be submitted.

Resourceful REST

Shopify is deprecating the Shopify Admin REST API which the Mechanic REST objects depend on. The first round of deprecations involve the product and variant endpoints. Read about the deprecation and . Use the going forward. The and objects will cease to work on on Feb 1, 2025 due to the changes being made by Shopify. Shopify will phase out the REST API completely over time, you can read more about this .

All of our will be ported to use GraphQL only, which will provide a model for how you can update your custom tasks. You'll be able to update your non-customized library tasks with a click of a button Please see these for migrating your custom tasks to GraphQL.

This usage style invokes the . It accepts an array of option values, containing these elements in order:

Explicit REST

Shopify is deprecating the Shopify Admin REST API which the Mechanic REST objects depend on. The first round of deprecations involve the product and variant endpoints. Read about the deprecation and . Use the going forward. The and objects will cease to work on on Feb 1, 2025 due to the changes being made by Shopify. Shopify will phase out the REST API completely over time, you can read more about this .

All of our will be ported to use GraphQL only, which will provide a model for how you can update your custom tasks. You'll be able to update your non-customized library tasks with a click of a button Please see these for migrating your custom tasks to GraphQL.

This usage style invokes . It accepts an array of option values, containing these elements in order:

Request path The entire, literal request path to use, including the requested β€” e.g. "/admin/api/2020-01/orders.json"

A JSON object of attributes In general, this means a wrapper object whose key is named after the current resource type, and whose value is the same set of data that would be used in the style

⚠️
⚠️
Shopify GraphQL Admin API
GraphQL variables
☺️
library tasks
guides
Shopify REST Admin API
☺️
library tasks
guides
Shopify REST Admin API
API version
here
here
product
variant
here
GraphQL
here
here
product
variant
here
GraphQL
resourceful
☺️
Shopify admin API
here
here
product
variant
here
library tasks
guides
HTTP
Interacting with Shopify
Shopify GraphQL Admin API
action
GraphQL
graphql_arguments