Help with Flow to assign tags to new products

I want to create a collection for newly published products that runs off a tag called “new”. I’ve tried to use Flow to add a tag called “new” to all products that were published less than 90 days ago … and remove that tag from all products published more than 90 days ago.

Sometimes there are products on the collection page but sometimes it is empty with no products: https://www.antiqueringboutique.com/collections/new-finds

The Flow to add the tags runs at 2.55pm EST. It sorts products by published date descending and then applies this in the edit query box to the first 100 products:

published_at:>'{{ scheduledAt | date_minus: "90 days" }}'

Then it adds the “new” tag to these.

The second Flow runs at the same time. It also sorts products by published date descending and then applies this in the edit query box to the first 100 products:

published_at:<'{{ scheduledAt | date_minus: "90 days" }}'

Note the > has become a <, otherwise it’s the same. The aim is to remove the “new” tag from any products published more than 90 days ago.

It seems like the 2nd Flow is removing the tag from all products as currently there are no products with the tag applied. But there were yesterday!! Any clues?!

The diagram

The action to remove the tag

Getting the products to remove the tag from

published_at is not a query filter on the API https://shopify.dev/docs/api/admin-graphql/2023-07/objects/QueryRoot#connection-queryroot-products

Therefore the query ignores it and returns everything.

Oh. Whoops. Thanks. So do I just change it to publishedAt, which IS a field under product in that link you shared. Or is this just not going to work …?

No, you can’t query any field, only those listed under “filters”. You might have to get creative with this, like putting the date it was published in a tag and then querying by that tag (unfortunately, querying by metafields is also not possible yet via API).

OK, thanks. The production person may kill me for making yet another tag, but I’ll give that a go. Thanks!

I’ve written a guide you can follow that includes links to download the flows I created.

You’d be looking at ‘step 3’ in the guide.

I use a run code block to determine if we consider the product a new arrival before tagging it. I do this based on the updateAt being a proxy for now, and compare it to the date the product was createdAt. If it’s less than 30 days old and it’s just being set to active, it’s a new arrival.

Only difference is that I’ve triggered this workflow based on product status updated. But you can still check out my code and adjust accordingly.

https://www.biscuitsbundles.com/blog/how-to-create-an-automated-new-arrivals-collection-with-shopify-flow

1 Like