Getting all InventoryLevels for location with GraphQL

Highlighted
Shopify Partner
7 0 0

I'm trying to get all the InventoryLevels for a Location using GraphQL. I look at the API docs https://help.shopify.com/en/api/graphql-admin-api/reference/object/location#inventorylevels-2019-10 and don't see how I can do that. It shows inventoryLevels connection, but that doesn't allow me to query all of it because the cursor doesn't change. Is there an API doc that shows how I can get all InventoryLevels for a Location that I'm missing, or how can I do this?

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 125

Hey @Jack_Chan ,

 

This query should get all the InventoryLevels for Locations using GraphQL:

 

query {
	location(id:"gid://shopify/Location/[Insert your Location ID Here]") {
        id
        inventoryLevels (first:50) {
      	pageInfo {
            hasNextPage
            hasPreviousPage
          }
          edges {
            cursor
            node {
              id
              item {
                sku
                variant {
                  title  
                }
              }
            }
          }
        }
      }
}

 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Shopify Partner
7 0 0

It looks like this would give the first 50 inventoryLevels though, is that right? I was trying to get a cursor so that I can continue iterating until hasNext is false.

0 Likes