Re: GraphQL barcode and sku search is not returning results for certain variants

Solved

GraphQL barcode and sku search is not returning results for certain variants

mahicks11
Tourist
6 0 3

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

 

 

 

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1453 238 511

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

View solution in original post

Replies 9 (9)

Planche95
Shopify Partner
4 0 1

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?

mahicks11
Tourist
6 0 3

Thanks for the reply.

 

Unfortunately, I haven't resolved the issue yet.

ShopifyDevSup
Shopify Staff
1453 238 511

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

mahicks11
Tourist
6 0 3

Hey @Kyle,

 

Thanks to you and support staff for fixing the issue. I can confirm that the barcode and sku queries are working again.

lukaszK
Shopify Partner
4 0 4

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. 

Etra
Shopify Partner
37 0 19

I have experienced this issue as well!

Etra
Shopify Partner
37 0 19

Yep this is a recent issue our app has experienced.

garyrgilbert
Shopify Partner
431 41 181

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

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
hsdonkin
Shopify Partner
19 1 8

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.

hsdonkin_0-1692373548951.png

hsdonkin_1-1692373570485.png

@ShopifyDevSup