Product Query to Filter Products With Sales

Hey Shopify Community.

Forgive me, I’m not a developer but usually manage to bodge together what we need through Shopify flows.

We have a problem where our Shopify gets clogged up with 1000’s of old unused products. Customers are able to create unique products through a 3rd party app.

I want to build a flow that archives products that are older than 84 days and have no sales. I noticed products have the insights which list sales, is there a way I can pull this through on a query?

this is my get product data query so far. I also need the product type. But how can I add the sales should be £0? (I want to keep any products that we have sold)

created_at:<=‘{{ scheduledAt | date_minus: “84 days” }}’ AND product_type:‘cpb_ordered’

Thank you so much!

2 Likes

Good job so far. There isn’t an API filter for products based on sales.

I think you could place a “get order data” step right after “Get product data”. And then search by the SKUs in one big list. The problem though is that you would then need to loop over that to find which skus matches.

An alternative that might be easier: build a workflow that starts on product added to store:

  • Product added to store
  • Run code (to check if date_created >= 84 days old). Similar example here
  • Condition
    • If > 84 days old and product_type = cpb_ordered
      • Archive product

Then go to the product list, sort by created_at, page back in time, select all the products, choose “…” and “Run Flow automation”. And run that workflow.

If you trust your filtering the Admin, you could also avoid even having that Run code and condition steps.

You can query orders by sku using graphql:

https://shopify.dev/docs/api/admin-graphql/2023-07/objects/order#queries