A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm using the following GraphQL queries to retrieve variants via barcode or sku. The queries work for the majority of the inventory but there are some variants that return 0 results despite having available inventory within Shopify at multiple locations. I am currently using GraphQL version 2022-10 and have even upgraded to 2023-04 and I still get no results.
FWIW, when I search for the variants in Shopify using barcode or sku, it works fine.
Here are the queries below:
Barcode Query:
$query = <<<'JSON'
query($barcode:String,$location:ID!)
{
productVariants(first: 1, query: $barcode) {
edges{
node{
id
product{
id
tags
title
featuredImage{
id
url
}
}
displayName
title
price
sku
barcode
inventoryQuantity
position
availableForSale
taxable
image{
id
url
altText
width
height
}
inventoryItem{
id
sku
unitCost{
amount
}
inventoryLevel(locationId:$location){
available
location{
id
}
}
}
createdAt
updatedAt
}
}
}
}
JSON
;
$postData = array();
$postData['query'] = $query;
$postData['variables'] = array ('barcode'=>$barcode.'*','location'=>$location);
SKU Query:
$query = <<<'JSON'
query($sku:String,$location:ID!)
{
productVariants(first: 25, query: $sku) {
edges{
node{
id
product{
id
tags
title
featuredImage {
id
url
altText
}
}
displayName
title
price
sku
barcode
inventoryQuantity
position
availableForSale
taxable
image{
id
url
altText
width
height
}
inventoryItem{
id
sku
unitCost{
amount
}
inventoryLevel(locationId:$location){
available
location{
id
}
}
}
createdAt
updatedAt
}
}
}
}
JSON
;
$postData = array();
$postData['query'] = $query;
$postData['variables'] = array ('sku'=>$sku.'*','location'=>$location);
Solved! Go to the solution
This is an accepted solution.
Hey @mahicks11 ! Thanks for letting us know about this. This issue has been resolved so the barcode query will be working now. If you notice it still occurring, reach out to our support team with specific details including your app, store, timeframe and any other specific details that will help us look further!
- Kyle G.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
I'm having very similar issue, and looks like it started yesterday! In my case, product is returned if I search by SKU, but it doesn't work if I use barcode.
Did you by chance resolve it already?
Thanks for the reply.
Unfortunately, I haven't resolved the issue yet.
This is an accepted solution.
Hey @mahicks11 ! Thanks for letting us know about this. This issue has been resolved so the barcode query will be working now. If you notice it still occurring, reach out to our support team with specific details including your app, store, timeframe and any other specific details that will help us look further!
- Kyle G.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hey @Kyle,
Thanks to you and support staff for fixing the issue. I can confirm that the barcode and sku queries are working again.
Hi,
We have also noticed that recently (last day we had a few reported issues related to this) productVariants is not able to find some variants. In our case we couldn't find them using sku, id nor title.
I have experienced this issue as well!
Yep this is a recent issue our app has experienced.
Similar issue has already been reported. Seems to be affecting the ProductVariants graphql query only. At least we all seem to be having problems with this query.
Got a couple public apps and a bunch of private apps where i use this query to synchronize products assigned to a location in a database. On Monday morning at 2am gmt+1 the query started returning about 1/3 of the results from the day before.. needless to say I'm still trying to put out the fires.
Cheers,
Gary
I'm also having this issue with the ProductVariants query! The weird thing for me is that sometimes the query seems to work in the GraphQL explorer app, but not for my GraphQL Client.