Mechanic is a development and ecommerce automation platform for Shopify. :)
This task demonstrates how a report can be requested from Report Toaster as a PDF. Once delivered, it is emailed to one or more recipients and/or sent to a Slack channel.
Runs Occurs when a user manually triggers the task and Occurs when a Report Toaster report is created. Configuration includes report id, email report recipients, slack incoming webhook url, message body, and run this task daily.
This task demonstrates how a report can be requested from Report Toaster as a PDF. Once delivered, it is emailed to one or more recipients and/or sent to a Slack channel.
You can use this task with any pre-built or custom report from Report Toaster by simply changing the report ID. Learn how to find your report ID here.
The report can be requested via CSV or PDF by changing the file format property. If the file format is omitted, the report results are returned as JSON directly within the task result.
See Mechanic's documentation on Report Toaster for more information.
The task can be run manually, or optionally, set to run as a daily report by checking the "Run this task daily" option. If a less frequent schedule is desired, then you may substitute the "mechanic/scheduler/daily" subscription with a different scheduler topic. See the Mechanic scheduler event topics for more details.
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?)
{% if options.run_this_task_daily__boolean %}
mechanic/scheduler/daily
{% endif %}
mechanic/user/trigger
report_toaster/reports/create{% comment %}
Preferred option order:
{{ options.report_id__required}}
{{ options.email_report_recipients__array }}
{{ options.slack_incoming_webhook_url }}
{{ options.message_body__multiline_required }}
{% endcomment %}
{% if options.email_report_recipients__array == blank and options.slack_incoming_webhook_url == blank %}
{% error "One or more email addresses or a Slack webhook must be defined." %}
{% endif %}
{% if event.preview %}
{% assign event = hash %}
{% assign event["data"] = hash %}
{% assign event["data"]["name"] = "A report name" %}
{% assign event["data"]["meta"] = hash %}
{% assign event["data"]["meta"]["task_id"] = task.id %}
{% assign event["data"]["file"] = hash %}
{% assign event["data"]["file"]["url"] = "http://www.google.com" %}
{% assign event["preview"] = true %}
{% endif %}
{% if event.topic contains "mechanic/scheduler/" or event.topic == "mechanic/user/trigger" or event.preview %}
{% action "report_toaster" %}
{
"operation": "report",
"reports": [
{
"id": {{ options.report_id__required | json }},
"file": {
"format": "pdf"
},
"meta": {
"task_id": {{ task.id | json }}
}
}
]
}
{% endaction %}
{% endif %}
{% if event.topic == "report_toaster/reports/create" or event.preview %}
{% if options.email_report_recipients__array != blank and event.data.meta.task_id == task.id %}
{% action "email" %}
{
"to": {{ options.email_report_recipients__array | join: "," | json }},
"subject": {{ event.data.name | append: " Report" | json }},
"body": {{ options.message_body__multiline_required | strip | newline_to_br | json }},
"reply_to": {{ shop.customer_email | json }},
"from_display_name": {{ shop.name | json }}
}
{% endaction %}
{% endif %}
{% if options.slack_incoming_webhook_url != blank and event.data.meta.task_id == task.id %}
{% action "http" %}
{
"method": "post",
"url": {{ options.slack_incoming_webhook_url | json }},
"body": {
"text": {{ options.message_body__multiline_required | strip | json }}
}
}
{% endaction %}
{% endif %}
{% endif %}Hello,
Your report is now available for download:
Report Name: {{ event.data.name }}
Download Link: {{ event.data.file.url }}
Enjoy!