Mechanic is a development and ecommerce automation platform for Shopify. :)
This task demonstrates Mechanic's ability to compile a CSV export, and send it as an email attachment. In this example, we bundle up a simple export of product titles and IDs, and email it as a CSV attachment.
Runs Occurs when a user manually triggers the task. Configuration includes email recipient.
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
{% comment %} -- create the initial array of arrays expected by the csv filter, and add the header row with column titles to it {% endcomment %} {% assign header_row = array | push: "Product ID", "Product Title" %} {% assign rows = array | push: header_row %} {% assign cursor = nil %} {% assign products = array %} {% for n in (1..100) %} {% capture query %} query { products( first: 250 after: {{ cursor | json }} ) { pageInfo { hasNextPage endCursor } nodes { legacyResourceId title } } } {% endcapture %} {% assign result = query | shopify %} {% if event.preview %} {% capture result_json %} { "data": { "products": { "nodes": [ { "legacyResourceId": "1234567890", "title": "Short sleeve t-shirt" } ] } } } {% endcapture %} {% assign result = result_json | parse_json %} {% endif %} {% for product in result.data.products.nodes %} {% assign row = array | push: product.legacyResourceId, product.title %} {% assign rows = rows | push: row %} {% endfor %} {% if result.data.products.pageInfo.hasNextPage %} {% assign cursor = result.data.products.pageInfo.endCursor %} {% else %} {% break %} {% endif %} {% endfor %} {% assign csv = rows | csv %} {% action "email" %} { "to": {{ options.email_recipient__email_required | json }}, "subject": {{ "Product ID export for " | append: shop.name | json }}, "body": "Please see attached. :)", "reply_to": {{ shop.customer_email | json }}, "from_display_name": {{ shop.name | json }}, "attachments": { "export.csv": {{ csv | json }} } } {% endaction %} {% log csv %}