Mechanic is a development and ecommerce automation platform for Shopify. :)
This task script demonstrates using the "http" action to retrieve external data, using a GET request. It also demonstrates saving the retrieved data to the Mechanic cache, where it can be used for future task runs.
Runs Occurs when a user manually triggers the task and Occurs when a Mechanic action is performed. Configuration includes save data to cache.
This task script demonstrates using the "http" action to retrieve external data, using a GET request. It also demonstrates saving the retrieved data to the Mechanic cache, where it can be used for future task runs.
Learn more about this technique: Can I load data from external sources?
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 "http" %} { "method": "get", "url": "http://example.com/config.txt" } {% endaction %} {% if options.save_data_to_cache__boolean %} {% comment %} For details on reading from the cache, see https://learn.mechanic.dev/platform/liquid/objects/cache {% endcomment %} {% log cached_config: cache.demonstration_config %} {% endif %} {% elsif event.topic == "mechanic/actions/perform" %} {% if event.preview %} {% comment %} For details on this technique, see https://learn.mechanic.dev/core/tasks/previews {% endcomment %} {% capture action_json %} { "type": "http", "run": { "result": { "body": "sample config" } } } {% endcapture %} {% assign action = action_json | parse_json %} {% endif %} {% if action.type == "http" %} {% assign config = action.run.result.body %} {% log retrieved_config: config %} {% if options.save_data_to_cache__boolean %} {% action "cache", "set", "demonstration_config", config %} {% endif %} {% endif %} {% endif %}