'how to get min price and max price of product in GraphQL with Bigcommerce
I am very new in Bigcommerce and I need min price and max price of product from in GraphQL query in Bigcommerce.
For Ex. like MySQL.
SELECT min(price),max(price) FROM `product`
Solution 1:[1]
Min & Max prices are within the retailPriceRange object, unded Product > Prices > retailPriceRange! You can see this from the GraphQL Explorer :) Something like this ...
{
...
prices {
price {
value
currencyCode
}
priceRange {
min {
value
currencyCode
}
max {
value
currencyCode
}
}
...
}
Solution 2:[2]
After reading your comment clarifying your question for Heather, I believe what you're wanting to do is get the lowest priced product and the highest priced product from your whole catalog.
Example: If you have 1000 products, you want to get the lowest priced product out of all of them, as well as the highest priced product.
If I'm understanding this correctly, there's not currently a way to make such a query in GraphQL. However, you can easily do this using the BigCommerce server-side API.
In order to do this with the server-side API, you'll need to utilize the sort, direction, and query parameters for the GET /v3/catalog/products API endpoint. (Reference)
I was able to accomplish this on my own store by making 2 API requests like so:
- GET /v3/catalog/products?limit=1&sort=price&direction=asc - This will fetch the lowest price product on my store.
- GET /v3/catalog/products?limit=1&sort=price&direction=desc - This will fetch the highest price product on my store.
Making the above two requests will get you the information you're looking for.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Jordan Arldt |

