Mechanic is a development and ecommerce automation platform for Shopify. :)
This task demonstrates how one might use the Files action to generate a file, using the fileCreate GraphQL mutation to transfer the resulting file to Shopify for storage.
Runs Occurs when a user manually triggers the task and Occurs when a Mechanic action is performed.
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
(By the way, have you seen our documentation? Have you joined the Slack community?)
mechanic/user/trigger mechanic/actions/perform
{% if event.topic == "mechanic/user/trigger" %} {% action "files" %} { "invoice.pdf": { "pdf": { "html": "<h1>Order #12345</h1>\n<p>It's due!</p>" } } } {% endaction %} {% elsif event.topic == "mechanic/actions/perform" %} {% if event.preview %} {% capture action_json %} { "type": "files", "run": { "result": { "invoice.pdf": { "url": "https://usemechanic.com/file/0000/invoice.pdf" } } } } {% endcapture %} {% assign action = action_json | parse_json %} {% endif %} {% if action.type == "files" %} {% action "shopify" %} mutation { fileCreate( files: [ { originalSource: {{ action.run.result["invoice.pdf"].url | json }} } ] ) { files { fileStatus fileErrors { code details message } } userErrors { code field message } } } {% endaction %} {% endif %} {% endif %}