Create a product inventory CSV feed, with Mechanic.

Mechanic is a development and ecommerce automation platform for Shopify. :)

Create a product inventory CSV feed

This task, paired with the linked instructions, creates a feed of product inventory (optionally filtering by product type).

Runs Occurs when a user manually triggers the task, Occurs every day at midnight (in local time), and Occurs every day at midnight (in local time), with a 12 hour delay. Configuration includes filter by product type.

15-day free trial – unlimited tasks

Documentation

This task, paired with the linked instructions, creates a feed of product inventory (optionally filtering by product type).

This task creates a regularly-updated feed, available at yourstore.com/pages/feed. Follow these required instructions to configure your store:

Tutorial: Creating scheduled CSV feeds

Note: This task fetches up to 30 variants per product.

Developer 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?)

Open source
View on GitHub to contribute to this task
Events
Occurs when a user manually triggers the task (mechanic/user/trigger)
Occurs every day at midnight (in local time) (mechanic/scheduler/daily)
Occurs every day at midnight (in local time), with a 12 hour delay (mechanic/scheduler/daily+12.hours)
Options
filter by product type
Code
{% assign csv = array %}
{% assign csv[0] = "Handle,Title,Option1 Name,Option1 Value,Option2 Name,Option2 Value,Option3 Name,Option3 Value,SKU,Quantity" | split: "," %}

{% assign cursor = nil %}
{% for n in (0..1000) %}
  {% capture query %}
    query {
      products(
        first: 15
        after: {{ cursor | json }}
        sortKey: CREATED_AT
        query: {% if options.filter_by_product_type == blank %}null{% else %}{{ options.filter_by_product_type | json | prepend: "product_type:" | json }}{% endif %}
      ) {
        pageInfo {
          hasNextPage
        }
        edges {
          cursor
          node {
            handle
            title
            variants(first: 30) {
              edges {
                node {
                  sku
                  inventoryQuantity
                  selectedOptions {
                    name
                    value
                  }
                }
              }
            }
          }
        }
      }
    }
  {% endcapture %}

  {% assign result = query | shopify %}

  {% for product_edge in result.data.products.edges %}
    {% assign product = product_edge.node %}

    {% for variant_edge in product.variants.edges %}
      {% assign variant = variant_edge.node %}

      {% assign row = array %}
      {% assign row[row.size] = product.handle %}
      {% assign row[row.size] = product.title %}
      {% assign row[row.size] = variant.selectedOptions[0].name %}
      {% assign row[row.size] = variant.selectedOptions[0].value %}
      {% assign row[row.size] = variant.selectedOptions[1].name %}
      {% assign row[row.size] = variant.selectedOptions[1].value %}
      {% assign row[row.size] = variant.selectedOptions[2].name %}
      {% assign row[row.size] = variant.selectedOptions[3].value %}
      {% assign row[row.size] = variant.sku %}
      {% assign row[row.size] = variant.inventoryQuantity %}

      {% assign csv[csv.size] = row %}
    {% endfor %}
  {% endfor %}

  {% if result.data.products.pageInfo.hasNextPage %}
    {% assign cursor = result.data.products.edges.last.cursor %}
  {% else %}
    {% break %}
  {% endif %}
{% endfor %}

{
  "action": {
    "type": "shopify",
    "options": [
      "create",
      "metafield",
      {
        "namespace": "mechanic",
        "key": "feed",
        "type": "multi_line_text_field",
        "value": {{ csv | csv | json }}
      }
    ]
  }
}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Filter by product type
Shirt