Is there a way to get the available inventory by location for each variant within a product from the Product ID with only 1 query?
I can do this with the Rest API but it requires a new request for each inventory_item_id and it’s very slow.
I’m thinking of something like this… but using the Product ID rather then the Variant ID.
{
productVariant(id: "gid://shopify/ProductVariant/31517938876468") {
inventoryItem {
id
inventoryLevels(first: 5) {
edges {
node {
location {
id
name
}
available
}
}
}
}
}
}
1 Like
Hello,
With the VariantId you can’t, but if you have the InevntoryItemId, and LocationId, you can:
query inventoryItem($id: ID!, $id2: ID!) {
location(id: $id) {
id
inventoryLevel(inventoryItemId: $id2) {
available
id
updatedAt
}
}
}
{
“id”: “gid://shopify/Location/80584757081”,
“id2”:“gid://shopify/InventoryItem/48698641645900”
}
Av18
November 6, 2024, 12:21pm
3
Hello @RfcSilva
I can not find any direct location field in the query inventoryItem. Can you please told me how can I get the inventory quantity of that inventory_item_id for specific location.?
Hello, @Av18 .
I have a similar requirement to retrieve the inventory for all items stocked in a location.
Did you ever get a reply to your question?
I selected all inventoryItems and then I use this query to get for each one. But in my case that works.
Now they changed the quantities location:
query inventoryItem($inventoryItemId: ID!, $locationId: ID!) {
inventoryItem(id: $inventoryItemId) {
id
variant {
product {
id
}
id
}
inventoryLevel(locationId: $locationId) {
id
location {
id
name
}
quantities (names: [""available""]) {
name
quantity
}
updatedAt
}
}
}