This guide explains how to retrieve and update product inventory. Because products can be stocked at multiple locations, the guide explains how to check where a product is stocked before explaining how to update inventory at a specific location.
Before you begin updating inventory, it's helpful to understand the relationships between the inventory resources:
Product Variant: Contains merchandising information, such as price, description, and images. Think of this as the product information that you might want a customer to see.
All product variants have a 1:1 relationship with their associated inventory item. Each product variant has one inventory item, and that inventory item belongs only to that product variant.
InventoryItem: Contains information about the physical product, such as its SKU. Think of this as the back-end information used for managing inventory, shipping, and fulfillments.
Inventory items are associated with one or many inventory levels. An inventory item will have an inventory level for each location where the item is stocked.
InventoryLevel: Represents the actual quantity of an item that is available.
Inventory levels connect one inventory item to one location. Each inventory level holds the available quantity for its inventory item at the associated location.
Location: Represents a geographical location where a merchant does business, such as a retail store or warehouse.
Locations can have many inventory levels. Each location has one inventory level for each inventory item that the location stocks.
How an order affects inventory
When a product variant that Shopify tracks is included in an order, Shopify decrements the inventory for that variant. Shopify doesn't know which location the item will be fulfilled from, so Shopify decrements the inventory level at the location that has the lowest ID.
When an order is fulfilled, the fulfillment includes the ID of the location where the fulfillment is taking place. Shopify checks whether the fulfillment location matches the original location where stock was decremented, and then adjusts the inventory if necessary:
- If the fulfillment location matches the original location, then no action is needed.
- If the fulfillment location doesn't match the original location, then Shopify decrements the inventory level at the fulfillment location and increments the inventory level at the original location.
Example: Inventory adjustments for a simple order
Rahul owns an online store. He uses two warehouses to stock his product inventory: one in Los Angeles (ID:
6884556842), and one in New York (ID:
13968834616). One of Rahul's products is a hat that's stocked at both locations with the following inventory levels:
- Los Angeles: 8
- New York: 6
A customer places an order for a hat. The Los Angeles location has the lowest ID, so Shopify decrements the item's inventory level at that location:
- Los Angeles: 7
- New York: 6
The order is actually fulfilled from the New York location. When the fulfillment is created, it includes the ID for the New York location. Shopify compares the fulfillment location ID to the original location and finds that they're different. Shopify then increments the inventory level at the Los Angeles location, and decrements the inventory level at the New York location:
- Los Angeles: 8
- New York: 5
Retrieve the inventory levels for a product variant
The following steps explain how to use the inventory resources to find the locations where a product variant is stocked and the inventory level at each location.
Step 1: Query a variant for its inventory item ID
Query a product variant to find the ID of its inventory item:
You can use the inventory item ID from the response to find the item's inventory levels.
Step 2: Retrieve the item's inventory levels
After you have the inventory item ID, you can use it with the InventoryLevel resource to find the levels and locations for the inventory item:
The response shows inventory levels at three locations with quantities of 8, 50, and 100 in stock.
Update inventory levels for a product variant
You can update inventory levels in two ways:
- Adjust the available quantity by incrementing or decrementing the value by a given amount.
- Set the available quantity to a given value.
Adjust inventory levels by a certain amount
Use the adjust endpoint with the location ID and inventory item ID to increase or decrease the available quantity for an inventory level:
adjustInventoryLevelQuantity mutation with the inventory level ID to adjust the available quantity for an inventory level:
Set inventory levels to a certain amount
Use the set endpoint with the location ID and inventory item ID to set an inventory level to a specific value.
There is no mutation to set levels directly using the GraphQL Admin API. Use the
adjustInventoryLevelQuantity mutation to adjust the inventory level instead.