Mechanic is a development 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 when a user triggers the task and when an 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, Gurus, 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.
{% 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://docs.usemechanic.com/article/370-the-cache-object {% 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://docs.usemechanic.com/article/335-preview-actions {% 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 %}