We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Graphql query products filtered by quantity

Solved

Graphql query products filtered by quantity

Swiftbee
Shopify Partner
14 0 1

How can i filter products based on quantity(low stock products < 10 not sold out) using admin graphql also i want total products with quantity less than 10.

Build Smarter Stores | Trusted Shopify Apps by Swiftbee
Single Code Discount – One code, multiple discounts! at just minimal price of 99 cents. Trusted by 1000+ stores
Ebay Importer by swiftbee– Import your eBay listings to Shopify in minutes.
Happy to help or answer app-related questions!Simplify your promotions.

Happy to help or answer app-related questions!
Accepted Solution (1)

CodingFifty
Shopify Partner
1102 162 191

This is an accepted solution.

Hey! @Swiftbee,

 

To filter products with inventory quantity less than 10 and not sold out using Shopify Admin GraphQL API, you need to query productVariants and filter based on inventoryQuantity. Here's an example:

{
  productVariants(first: 100, query: "inventory_quantity:<10 AND inventory_quantity:>0") {
    edges {
      node {
        id
        title
        inventoryQuantity
        product {
          title
          id
        }
      }
    }
  }
}

This query fetches variants with quantity between 1 and 9. To get the total count, you can use productVariants with query: and access pageInfo or keep paginating while counting manually, as GraphQL doesn't return total count directly.

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com

View solution in original post

Reply 1 (1)

CodingFifty
Shopify Partner
1102 162 191

This is an accepted solution.

Hey! @Swiftbee,

 

To filter products with inventory quantity less than 10 and not sold out using Shopify Admin GraphQL API, you need to query productVariants and filter based on inventoryQuantity. Here's an example:

{
  productVariants(first: 100, query: "inventory_quantity:<10 AND inventory_quantity:>0") {
    edges {
      node {
        id
        title
        inventoryQuantity
        product {
          title
          id
        }
      }
    }
  }
}

This query fetches variants with quantity between 1 and 9. To get the total count, you can use productVariants with query: and access pageInfo or keep paginating while counting manually, as GraphQL doesn't return total count directly.

Coding Fifty || Shopify Partner
For any custom section queries, please visit: Fiverr Profile
Found my response useful? Like it and mark as Accepted Solution!
For additional discussions, reach out via: Email ID: codingfifty@gmail.com