Delete all products with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Delete all products

by Isaac Bowen (team@usemechanic.com)

Use this task to quickly (and permanently) clear out your product list. Optionally, filter by a specific query, so as to only delete specific products from your store. Supports a test mode, allowing you to see exactly what products you can expect Mechanic to delete.

Runs when a user triggers the task. Configuration includes query, test mode, and live mode.

15-day free trial – unlimited tasks

Documentation

Use this task to quickly clear out your product list.

Caution: if you leave the query option empty, this task will delete every product in your store.

Use the "query" setting to get specific about what products you want to delete. Tick the "Test mode" checkbox to verify which products will be deleted: after saving, use the "Run task" button to run the product scan, and you'll receive a list of products that Mechanic would have deleted in live mode. Once you're ready, uncheck the "Test mode" box and check the "Live mode" box, save the task, then use "Run task" to permanently delete all matching products.

Example queries:

  • product_type:Shirt
  • tag:old

Learn more:

Developer details

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.

Events
when a user triggers the task (mechanic/user/trigger)
Options
query, test mode (boolean), live mode (boolean)
Script
{% assign product_ids_and_titles = hash %}

{% assign cursor = nil %}
{% for n in (0..100) %}
  {% capture query %}
    query {
      products(
        first: 250
        after: null
        sortKey: TITLE
        query: {{ options.query | json }}
      ) {
        pageInfo {
          hasNextPage
        }
        edges {
          cursor
          node {
            title
            legacyResourceId
          }
        }
      }
    }
  {% endcapture %}

  {% assign result = query | shopify %}

  {% for product_edge in result.data.products.edges %}
    {% assign product_ids_and_titles[product_edge.node.legacyResourceId] = product_edge.node.title %}
  {% endfor %}

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

{% if event.preview %}
  {% assign product_ids_and_titles = '{"1234567890": "Short Sleeve T-Shirt"}' | parse_json %}
{% endif %}

{% if options.test_mode__boolean and options.live_mode__boolean %}
  {"error": "Please choose either test mode or live mode. (We use two separate checkboxes, as a safeguard.)"}
{% elsif options.test_mode__boolean == false and options.live_mode__boolean == false %}
  {"error": "Please choose either test mode or live mode. (We use two separate checkboxes, as a safeguard.)"}
{% elsif options.test_mode__boolean %}
  {% capture message %}
    The test scan resulted in {{ product_ids_and_titles.size }} product(s).
    {% for keyval in product_ids_and_titles %}
      {{ forloop.index }}. {{ keyval[1] }} (https://{{ shop.domain }}/admin/products/{{ keyval[0] }})
    {% endfor %}
  {% endcapture %}
  {% assign message = message | unindent | strip %}

  {% action "echo" message %}
{% elsif options.live_mode__boolean %}
  {% for keyval in product_ids_and_titles %}
    {% action "shopify" %}
      [
        "delete",
        ["product", {{ keyval[0] | json }}]
      ]
    {% endaction %}
  {% endfor %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Test mode
true