All things Shopify and commerce
My goal is to send a Storefront API request that allows be to grab X first products based on collection handle that are filtered by min/max price and title search. However, this doesn't seem to be possible right now.
Currently, I am able to achieve this partially requiring client-side filtering outside of the request.
Method: Use the collection query with the handle filter, but the ProductsConnection it returns does not allow for the query parameter to be used in the subsequent products query.
{
"query": "query getProducts($handle: String!, $first: Int, $sortKey: ProductCollectionSortKeys, $reverse: Boolean, $query: String) { collection(handle: $handle) { products(first: $first, sortKey: $sortKey, reverse: $reverse, query: $query) { edges { node { id title description handle availableForSale onlineStoreUrl variants(first: 10) { edges { node { id title sku availableForSale priceV2 { amount currencyCode } compareAtPriceV2 { amount currencyCode } } } } featuredImage { altText url height width } } } } } }",
"variables": {
"handle": "shirts",
"first": 1,
"query": "title: *t*"
}
}
This query returns the error:
{
"errors": [
{
"message": "Field 'products' doesn't accept argument 'query'",
"locations": [
{
"line": 1,
"column": 216
}
],
"path": [
"query getProducts",
"collection",
"products",
"query"
],
"extensions": {
"code": "argumentNotAccepted",
"name": "products",
"typeName": "Field",
"argumentName": "query"
}
},
{
"message": "Variable $query is declared by getProducts but not used",
"locations": [
{
"line": 1,
"column": 1
}
],
"path": [
"query getProducts"
],
"extensions": {
"code": "variableNotUsed",
"variableName": "query"
}
}
]
}
This makes sense because in the docs the ProductConnection doesn't allow for query, but I don't understand why. Is there any way this can be added so I don't have to make multiple requests and then have to filter client-side?
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024