Inventory Module

The Inventory Module provides inventory-related features in your Medusa and Node.js applications.

How to Use Inventory Module's Service#

You can use the Inventory Module's main service by resolving from the Medusa container the resource Modules.INVENTORY imported from @medusajs/framework/utils.

For example:


Features#

Inventory Items Management#

Store and manage inventory of any stock-kept item, such as product variants.

Inventory items hold details of the underlying stock-kept item, as well as inventory details such as whether the item requires shipping.

Code
1const inventoryItem = await inventoryModuleService.createInventoryItems({2  sku: "SHIRT",3  title: "Green Medusa Shirt",4  requires_shipping: true,5})

Inventory Across Locations#

Inventory items' quantities are set per locations through inventory levels.

This gives you more flexibility in managing the quantity of a stock-kept item across different locations, such as different warehouses.

Code
1const inventoryLevel = await inventoryModuleService.createInventoryLevels([2  {3    inventory_item_id: "iitem_123",4    location_id: "sloc_123",5    stocked_quantity: 20,6  },7])

Reservation Management#

Reserve quantities of inventory items at specific locations for orders or other purposes.

The reserved quantity isn't considered for purchase, but can be deleted to revert the reservation.

Code
1const reservationItem = await inventoryModuleService.createReservationItems([2  {3    inventory_item_id: "iitem_123",4    location_id: "sloc_123",5    quantity: 10,6  },7])

Check Inventory Availability#

Check whether an inventory item has the necessary quantity for purchase.

Any reserved quantity is considered unavailable.

Code
1const isAvailable = await inventoryModuleService.confirmInventory(2  inventoryItemId,3  [locationId],4  neededQuantity5)
Was this page helpful?
Edit this page