I want to grab all products that have inventory because for my application, it does not make sense on out-of-stock products.
Is it possible to get all products with inventory count greater than zero? if so, how do I do this?
I want to grab all products that have inventory because for my application, it does not make sense on out-of-stock products.
Is it possible to get all products with inventory count greater than zero? if so, how do I do this?
Depends whether you need that on a product or variant level. Not aware of how to do this in one query on variant level. For products you can
{
products(first: 250, query: "available_for_sale:true") {
edges {
node {
id
title
availableForSale
variants(first: 100) {
edges {
node {
id
title
availableForSale
}
}
}
}
}
}
}
Mind you, that the query filter used
available_for_sale:true
is not documented. But then again, those that are such as inventory_total and out_of_stock_somewhere simply do not work.
Hope this helps!
@KarlOffenberger : Looks like there’s no other way to use available_for_sale unless I use the GraphQL API, which I was avoiding since my infrastructure isn’t ready for it right now but for a 1-off kind of call it may be possible to write this as a temporary solution. Thanks.
For REST API, you could create an automated collection with a condition such as Inventory level is greater than 0 and then use Collect API to get the products. It would still only account for products where at least 1 of its variants’ inventory levels is greater than 0, but gets you a bit closer.
I ended up just using the Product API to get all products and filtering out all products that have inventory_quantity = 0. It’s a bit less efficient than having the shopify api do it, but i can optimize in the future
Sure, if it works don’t fix it. Though I’d really consider the collection and Collect API as it’s simple to setup and use and you do not have to fetch 'em all. If you still stay with the fetch 'em all approach, at least try to limit the fields you request to those you really need.