Shopify
Run Shopify GraphQL mutations from Mechanic tasks — create orders, update products, manage customers, and more via the Shopify action.
The Shopify action sends requests to the Shopify Admin API. Use the shopify Liquid filter to read data; use this action to write or update data. Use GraphQL for new Shopify automation work.
Options
This action has several usage styles, each with a different set of constraints on action options.
GraphQL
This usage style invokes the Shopify GraphQL Admin API. In this style, a single GraphQL query string is supplied as the action options. The action tag has specific support for this action type, allowing this string to be provided as the contents of an action block.
{% action "shopify" %}
mutation {
customerCreate(
input: {
email: "test@example.com"
}
) {
customer {
id
}
userErrors {
field
message
}
}
}
{% endaction %}GraphQL with variables
This usage style invokes the Shopify GraphQL Admin API, and supports combining GraphQL queries with GraphQL variables. 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.
query
Required; a string containing a GraphQL query
variables
Required; a JSON object mapping variable names to values
Basic example
Complex example
This example shows how the query and variables may be built up separately, and provided to the action using concise tag syntax.
Bulk operations
The Shopify action can start Shopify bulk operations using bulkOperationRunQuery or bulkOperationRunMutation. Mechanic detects the returned bulk operation, monitors it, and re-invokes the same task with mechanic/shopify/bulk_operation when Shopify finishes.
Bulk operation mutations require a staged JSONL variables upload before calling bulkOperationRunMutation. Use the HTTP action for the multipart upload step, and use mechanic/actions/perform to move between the staged upload, file upload, and mutation-start steps.
Related
Reading Shopify data — query products, orders, customers, and more using GraphQL in Liquid
Writing Shopify data — overview of writing data to Shopify
Responding to action results — inspect Shopify mutation results in a follow-up task run
Preventing action loops — guard against re-triggers when modifying resources you subscribe to
Last updated
Was this helpful?