Query products that belong to a collection

Solved
carl-mgp
Shopify Partner
4 0 0

i'm trying to set up a shopify flow where the first step is to query products that belong to a particular collection. looking at the documentation here though

 

https://shopify.dev/docs/api/storefront/2023-04/queries/products

 

it looks like there's no query argument available for me to query if a product belongs to a collection

 

then looking on the opposite side where i query collections by title to get their products, 

 

https://shopify.dev/docs/api/storefront/2023-04/queries/collections

 

it looks likes the products are at a lower level and i'm not sure how to retrieve that. i was thinking of querying collections then try looping through the collection results but "for each" actions don't accept "Get data" actions. 

 

is it possible for me to get those products via shopify flow query syntax only?

 

thanks

Accepted Solution (1)
paul_n
Shopify Staff
Shopify Staff
603 97 154

This is an accepted solution.

FYI, that's the wrong query documentation. Flow uses the Admin API. https://shopify.dev/docs/api/admin-graphql/2023-04/queries/products

 

But the point still holds - you can't query products by collections. You could query collections or the same criteria used for a collection. In For each, you can actually loop over those items returned by "Get data", but there is a current limit of looping over a single level (so you can't loop over collections and then products). 

 

What are you hoping to do with this workflow? It may be that there is another solution that will work for you. For example, you may be able to use a trigger and then fetch data rated to that trigger.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 4 (4)
paul_n
Shopify Staff
Shopify Staff
603 97 154

This is an accepted solution.

FYI, that's the wrong query documentation. Flow uses the Admin API. https://shopify.dev/docs/api/admin-graphql/2023-04/queries/products

 

But the point still holds - you can't query products by collections. You could query collections or the same criteria used for a collection. In For each, you can actually loop over those items returned by "Get data", but there is a current limit of looping over a single level (so you can't loop over collections and then products). 

 

What are you hoping to do with this workflow? It may be that there is another solution that will work for you. For example, you may be able to use a trigger and then fetch data rated to that trigger.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
carl-mgp
Shopify Partner
4 0 0

I wanted to check if it's possible to do these queries with manual collections but it looks like my original idea with tags and automatic collections is the way to go. 

 

thanks

gkennedy
Shopify Partner
4 0 0

Hi Paul,

I'm looking for this too so I'll share my use case.

I'd like to use Flow to keep a "New Arrivals" collection up to date. I have set up a flow to get the top 100 products by create date descending and add them to the collection but I need a corresponding workflow to remove the older ones (or clear the collection of all products first).

Open to any way to solve the New Arrivals collection issue, just trying out Flow as it seemed like it might be capable.

 

paul_n
Shopify Staff
Shopify Staff
603 97 154

Could you instead use a dynamic collection that is based on a product tag? Then you could use flow to set / remove that tag. Tags can also be a query filter.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.