Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Inventory Level ID

Solved

Inventory Level ID

MuhammedF
Tourist
4 0 1

Can anyone help me on how to find the InventoryLevel ID and ItemVariant ID on Shopify ? 

This is to work on an integration to update the stock inventory on Shopify using InventoryLevels API.

MohammedFahim_0-1648108272538.png

 

Accepted Solution (1)

rohankamble
Shopify Partner
2 1 1

This is an accepted solution.

Below is the query I used to get inventoryLevelId for a product.

The product for which I wanted to get inventoryLevelId was just the main product with no variants

 

So first I listed down the product Variants using the below query

query {
  productVariants(first: 10) {
    edges {
      node {
        id
        displayName
      }
    }
  }
}

 

and then used the productVariant Id of one of the products to get its inventoryLevelId

query {
  productVariant(id: "gid://shopify/ProductVariant/40766402265165") {
    id
    title
    inventoryItem {
      id
      inventoryLevels(first: 10) {
        edges {
          node {
            id
            location {
              id
              name
            }
          }
        }
      }
    }
  }
}

 

View solution in original post

Replies 3 (3)

hugo4711
Shopify Partner
17 1 1

This does not seem possible (at least for the InventoryItem) and is most likely an error in the GraphQL-Specification:

 

Here is the GraphQL-Spec including an example (but there is no way to retrieve the ID):
https://shopify.dev/api/admin-graphql/2022-04/queries/inventoryLevel

 

The REST-API with the respective GET request states that inventory_level_ids and location_ids need to be provided:
https://shopify.dev/api/admin-rest/2022-04/resources/inventorylevel#get-inventory-levels

 

But there is no possibility in the GraphQL-API...


An InventoryLevel really has a compound primary key: the location_id and the inventory_item_id 

So I think that this is a bug in the GraphQL-API

orloff
Shopify Partner
26 0 16

if you want get inv Level Id and locations by GraphQL, you can get it by product variant request:
 

variants(first:10){
                    edges {
                        node {
                        inventoryItem{
                            inventoryLevels(first:2) {edges {node {id location {id}}}}
                            }
                        }
                    }   
                }

 

rohankamble
Shopify Partner
2 1 1

This is an accepted solution.

Below is the query I used to get inventoryLevelId for a product.

The product for which I wanted to get inventoryLevelId was just the main product with no variants

 

So first I listed down the product Variants using the below query

query {
  productVariants(first: 10) {
    edges {
      node {
        id
        displayName
      }
    }
  }
}

 

and then used the productVariant Id of one of the products to get its inventoryLevelId

query {
  productVariant(id: "gid://shopify/ProductVariant/40766402265165") {
    id
    title
    inventoryItem {
      id
      inventoryLevels(first: 10) {
        edges {
          node {
            id
            location {
              id
              name
            }
          }
        }
      }
    }
  }
}