Issue getting inventory data for newly created prouct

Remie_Malik
Shopify Partner
8 1 0

Hi,

Our wms uses webhooks to post new stock levels to our Shopify app.
Our Shopify app will try to find the product by Sku and will also fetch the inventoryItem using a GraphQl Query.

However it seems that when a product is less then a day old the information will not be fetched correctly the first time.
The response will remain empty and as a result we cannot update to stock information for our client.

We use the following query to fetch necessary data for creating a new inventory_level entry:

 

Query {
	productVariants(first: 1, query: "sku:\"$sku\"") {
	    edges {
		node {
		    inventoryItem {
		        legacyResourceId
		        inventoryLevels(first:5) {
		            edges {
		                node {
		                    available   
		                }
		            }   
		        } 
		    }
		}
	    }
	}
}

 

 

This GraphQL query results in a empty response for a product which is less then a day old. 
Can anyone confirm this? Should we handle new product different then existing products?

 

Thanks in advance for any  responses/answers.

 

If you need more information, please ask!

 

Thanks.

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

I wonder if it has to do with how you are passing along the SKU variable. Here's an example, where I created a new product in the web admin, query for it against its hardcoded SKU, and query for it using the SKU variable how you've defined it in your example. 

New SKU.jpgGQL Okay.jpgGQL Bad.jpg 

0 Likes
Remie_Malik
Shopify Partner
8 1 0

The query shown in the example is created in PHP. so its a variable passed into the string. the resulting query would look like this:

 

{
  productVariants(first: 1, query: "sku:\"KS1782-rose-1m\"") {
    edges {
      node {
        inventoryItem {
          legacyResourceId
          id
          inventoryLevels(first: 5) {
            edges {
              node {
                available
              }
            }
          }
        }
      }
    }
  }
}

 

We are surrounding the sku with double quotes because we had issues retrieving products with spaces in it. 
The query as shown is working for all products. except for products which are created within the last 24 hours or so.

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

Gotcha. If you look at the screen shot of the example that worked, you'll see I don't wrap the SKU value in quotes. So it would just be 

"sku:KS1782-rose-1m"

 right?

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

This worked as well. I define the entire query string as a query variable. Hope this helps!

Untitled.png

0 Likes
Remie_Malik
Shopify Partner
8 1 0

I dont think this fixes the issue of trying to get the inventory data for new products. Or the inconsistency of it.

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 227

Not sure I'm following you...the examples I provided worked based on what I saw. If you are looking to just fetch newly-created products there are ways you can fetch a set of them based on their "date in-stock", in addition to just pulling by specific SKU. Take a peek around the GraphQL API docs and you'll see there is nice functionality!

0 Likes