What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

how to query inventory levels

how to query inventory levels

RedYellowBlue
Shopify Partner
17 0 3

Hi, 

 

I'm developing a order management app to create fulfilment orders at a 3th party logistics provider. 

So far I am able to:

Query the orders. 

I created a Fulfilment Service. 
I can request locations and inventory levels. 

The main question now is how I can relate line_items from the order to inventory levels. 
When I query an order, I get data like:
sku, product_id, variant_id

To retrieves a list of inventory levels, I need to have inventory_item_ids. 
Or when I query inventory levels, I receive an inventory_item_id and location_id, but how do I know which products are related to these inventory and location id's?

regards Peter

Replies 4 (4)

RedYellowBlue
Shopify Partner
17 0 3

According to: https://shopify.dev/docs/api/admin-rest/2022-04/resources/inventorylevel#get-inventory-levels?locati...

"Each product variant has one inventory item, and that inventory item belongs only to that product variant."
How can I find this 1:1 inventory item id?

 

 

snakecase
Shopify Partner
18 4 8

You can't get the relationship directly from the inventoryLevel. You have to request the inventoryItem. the inventoryItem is the data structure encapsulating the inventoryLevel. You can at the same time request the variant of an inventoryItem and then get the variant id.

 

I hope that help

snakecase
Shopify Partner
18 4 8

I just realized that you are using the REST API and not the GraphQL API. My solution doesn't work for you. Sorry about that

snakecase
Shopify Partner
18 4 8

After a bit of digging, it looks like the only way with REST API is to get the inventory_item_id via the Product Variant request

 

I hope it will help you (this time)