We are using the productVariants GraphQL query to retrieve variants and their inventoryLevels. However, sometimes the inventory levels are missing in the API response.
Can someone help me understand why this is happening?
Here is my query:
productVariants(first: $first, after: $after, query: $query) {
edges {
node {
product {
id
}
id
inventoryItem {
id
inventoryLevels(first:250) {
edges {
node {
id
quantities (names:"available") {
quantity
}
location {
id
}
}
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
Sorry I’m a bit confused, is what from a verified source?
What are you doing in the different queries? It looks like the second one you are filtering to only a single location.
Yes you may only need available, but it still should be a list of string as per the docs. quantities(names: ["available"] for example. This could be impacting the results as well. InventoryLevel - GraphQL Admin
Sorry if I wasn’t clear. I was trying to find a verified source where the following information is mentioned:
“If the product isn’t stocked at a location or inventory isn’t tracked, then it won’t show up.”
Also, I understand your point about wrapping the “available” string in brackets. I’ve verified that if you are using a single quantity type, you can use it without brackets. However, I can try adding the brackets in case this is the reason for the missing inventoryLevels.
That said, I am not sure this should cause the data to be completely omitted; I would have expected an error instead.
@JordanFinners do you have more input on this or my last feedback? I tried by adding a quantity filter as (names: [“available”]), still facing the same issue.
I don’t think it says it explicitly anywhere. But it is logical that if a product isn’t stocked at a location or inventory isn’t tracked. The API returning inventory levels for that product wouldn’t show those because it doesn’t know them.
In terms of why your queries are returning different data, is one looking only at a specific location? Because your second results only have one location.
If you can provide both queries and example inputs that would help.
No, it does not look at a specific location. As per the query posted above, I am trying to retrieve information on variants based on the provided product_ids.
My only concern with the returned data is that it’s inconsistent; sometimes it includes inventory levels and sometimes it doesn’t, even with the same query and parameters. I am just trying to figure out whether this is a bug or expected behavior.
Here is the query that returns a response with either two inventory levels or sometimes only one.
Are you using the same exact query and also query variable for both of those responses you screenshotted? As the query above doesn’t contain all the fields in the response.
Yes, I am using the same query. I had actually shortened it when pasting it here by removing some off-topic fields.
Anyway, if you’d like to see the full query, here it is. This is the exact query I am using, and it’s producing the same results as shown in the screenshot I shared earlier:
productVariants(first: $first, after: $after, query: $query) {
edges {
node {
product {
id
}
id
title
sku
price
barcode
compareAtPrice
selectedOptions {
name
value
}
inventoryQuantity
inventoryItem {
id
countryCodeOfOrigin
harmonizedSystemCode
unitCost {
amount
}
measurement {
weight {
value
unit
}
}
inventoryLevels(first:250) {
edges {
node {
id
quantities (names:"available") {
quantity
}
location {
id
}
}
}
}
}
metafields(first: 200) {
edges {
node {
id
key
value
type
namespace
}
}
}
media(first: 250) {
edges {
node {
... on MediaImage {
id
image {
url
}
}
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
Thanks! What query string are you using for these? For the GraphQL variable query.
Wondering if location was included or something in the second set of results to only include that location for inventory
Can you check in Shopify Admin on the product to see if someone has removed the location that the product is stocked at? As that could have occurred between you query run.
Also if you are looking at just getting the data for a single product, I’d recommend using a simpler query, or one returning more concise media/metafields as this query cost is also potentially very expensive, having run it myself, it could use up to 700 of your points.
I could only find that the product/variant attached to the stock location has never had any inventory adjustments or edits for that location. It seems they were just linked to the product/variant without any actual updates.
Do you think this could be the reason why that location is missing in the GraphQL response?