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);
