Storefront API - filtering on 'in stock only'

dev88
Tourist
11 0 6

Hi guys,

 

Is there a way to filter products that are 'in stock only' in my storefront api call? Can you show me an example?

Replies 2 (2)

dev88
Tourist
11 0 6

Found it 🙂

 

{
   shop {
       products(first: 10, query: "published_status:published AND available_for_sale:true")

   }

}

oscprofessional
Shopify Partner
15846 2371 3074

Hello 
i) Using Admin Product API you can get all products array. used below Admin API to get Products

'store_url/admin/products.json'

ii) get the "variants" from products array
iii) get "inventory_quantity" from "variants" array
iv) if "inventory_quantity" is grater than "0" then product is "In Stock" otherwise product is "Out of Stock"

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Custom Pricing Wholesale App : Free | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing