IInventoryService
Methods
adjustInventory
**adjustInventory**(inventoryItemId, locationId, adjustment, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)>
This method is used to adjust the inventory level's stocked quantity. The inventory level is identified by the IDs of its associated inventory item and location.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function adjustInventory (
inventoryItemId: string,
locationId: string,
adjustment: number
) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevel = await inventoryModule.adjustInventory(
inventoryItemId,
locationId,
adjustment
)
// do something with the inventory level or return it.
}
Parameters
inventoryItemId
stringRequiredlocationId
stringRequiredadjustment
numberRequiredcontext
SharedContextReturns
Promise<InventoryLevelDTO>
confirmInventory
**confirmInventory**(inventoryItemId, locationIds, quantity, context?): Promise<boolean>
This method is used to confirm whether the specified quantity of an inventory item is available in the specified locations.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function confirmInventory (
inventoryItemId: string,
locationIds: string[],
quantity: number
) {
const inventoryModule = await initializeInventoryModule({})
return await inventoryModule.confirmInventory(
inventoryItemId,
locationIds,
quantity
)
}
Parameters
inventoryItemId
stringRequiredlocationIds
string[]Requiredquantity
numberRequiredcontext
SharedContextReturns
Promise<boolean>
Promise
Promise<boolean>RequiredcreateInventoryItem
**createInventoryItem**(input, context?): Promise<[InventoryItemDTO](/references/services/types/InventoryItemDTO)>
This method is used to create an inventory item.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createInventoryItem (item: {
sku: string,
requires_shipping: boolean
}) {
const inventoryModule = await initializeInventoryModule({})
const inventoryItem = await inventoryModule.createInventoryItem(
item
)
// do something with the inventory item or return it
}
Parameters
context
SharedContextReturns
Promise<InventoryItemDTO>
createInventoryItems
**createInventoryItems**(input, context?): Promise<[InventoryItemDTO](/references/services/types/InventoryItemDTO)[]>
This method is used to create inventory items.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createInventoryItems (items: {
sku: string,
requires_shipping: boolean
}[]) {
const inventoryModule = await initializeInventoryModule({})
const inventoryItems = await inventoryModule.createInventoryItems(
items
)
// do something with the inventory items or return them
}
Parameters
context
SharedContextReturns
Promise<InventoryItemDTO[]>
createInventoryLevel
**createInventoryLevel**(data, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)>
This method is used to create inventory level.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createInventoryLevel (item: {
inventory_item_id: string
location_id: string
stocked_quantity: number
}) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevel = await inventoryModule.createInventoryLevel(
item
)
// do something with the inventory level or return it
}
Parameters
context
SharedContextReturns
Promise<InventoryLevelDTO>
createInventoryLevels
**createInventoryLevels**(data, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)[]>
This method is used to create inventory levels.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createInventoryLevels (items: {
inventory_item_id: string
location_id: string
stocked_quantity: number
}[]) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevels = await inventoryModule.createInventoryLevels(
items
)
// do something with the inventory levels or return them
}
Parameters
context
SharedContextReturns
Promise<InventoryLevelDTO[]>
createReservationItem
**createReservationItem**(input, context?): Promise<[ReservationItemDTO](/references/services/types/ReservationItemDTO)>
This method is used to create a reservation item.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createReservationItem (item: {
inventory_item_id: string,
location_id: string,
quantity: number
}) {
const inventoryModule = await initializeInventoryModule({})
const reservationItem = await inventoryModule.createReservationItems(
item
)
// do something with the reservation item or return them
}
Parameters
context
SharedContextReturns
Promise<ReservationItemDTO>
createReservationItems
**createReservationItems**(input, context?): Promise<[ReservationItemDTO](/references/services/types/ReservationItemDTO)[]>
This method is used to create reservation items.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function createReservationItems (items: {
inventory_item_id: string,
location_id: string,
quantity: number
}[]) {
const inventoryModule = await initializeInventoryModule({})
const reservationItems = await inventoryModule.createReservationItems(
items
)
// do something with the reservation items or return them
}
Parameters
context
SharedContextReturns
Promise<ReservationItemDTO[]>
deleteInventoryItem
**deleteInventoryItem**(inventoryItemId, context?): Promise<void>
This method is used to delete an inventory item or multiple inventory items. The inventory items are only soft deleted and can be restored using the restoreInventoryItem method.
Example
Parameters
inventoryItemId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequireddeleteInventoryItemLevelByLocationId
**deleteInventoryItemLevelByLocationId**(locationId, context?): Promise<void>
This method deletes the inventory item level(s) for the ID(s) of associated location(s).
Example
Parameters
locationId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequireddeleteInventoryLevel
**deleteInventoryLevel**(inventoryItemId, locationId, context?): Promise<void>
This method is used to delete an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
Example
Parameters
inventoryItemId
stringRequiredlocationId
stringRequiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequireddeleteReservationItem
**deleteReservationItem**(reservationItemId, context?): Promise<void>
This method is used to delete a reservation item or multiple reservation items by their IDs.
Example
Parameters
reservationItemId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequireddeleteReservationItemByLocationId
**deleteReservationItemByLocationId**(locationId, context?): Promise<void>
This method deletes reservation item(s) by the ID(s) of associated location(s).
Example
Parameters
locationId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequireddeleteReservationItemsByLineItem
**deleteReservationItemsByLineItem**(lineItemId, context?): Promise<void>
This method is used to delete the reservation items associated with a line item or multiple line items.
Example
Parameters
lineItemId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequiredlistInventoryItems
**listInventoryItems**(selector, config?, context?): Promise<[[InventoryItemDTO](/references/services/types/InventoryItemDTO)[], number]>
This method is used to retrieve a paginated list of inventory items along with the total count of available inventory items satisfying the provided filters.
Example
To retrieve a list of inventory items using their IDs:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryItems (ids: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryItems, count] = await inventoryModule.listInventoryItems({
id: ids
})
// do something with the inventory items or return them
}
To specify relations that should be retrieved within the inventory items:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryItems (ids: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryItems, count] = await inventoryModule.listInventoryItems({
id: ids
}, {
relations: ["inventory_level"]
})
// do something with the inventory items or return them
}
By default, only the first 10
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryItems (ids: string[], skip: number, take: number) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryItems, count] = await inventoryModule.listInventoryItems({
id: ids
}, {
relations: ["inventory_level"],
skip,
take
})
// do something with the inventory items or return them
}
Parameters
config
FindConfig<InventoryItemDTO>select
or relations
, accept the attributes or relations associated with a inventory item.context
SharedContextReturns
Promise<[InventoryItemDTO[], number]>
listInventoryLevels
**listInventoryLevels**(selector, config?, context?): Promise<[[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)[], number]>
This method is used to retrieve a paginated list of inventory levels along with the total count of available inventory levels satisfying the provided filters.
Example
To retrieve a list of inventory levels using their IDs:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryLevels (inventoryItemIds: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
inventory_item_id: inventoryItemIds
})
// do something with the inventory levels or return them
}
To specify relations that should be retrieved within the inventory levels:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryLevels (inventoryItemIds: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
inventory_item_id: inventoryItemIds
}, {
relations: ["inventory_item"]
})
// do something with the inventory levels or return them
}
By default, only the first 10
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryLevels (inventoryItemIds: string[], skip: number, take: number) {
const inventoryModule = await initializeInventoryModule({})
const [inventoryLevels, count] = await inventoryModule.listInventoryLevels({
inventory_item_id: inventoryItemIds
}, {
relations: ["inventory_item"],
skip,
take
})
// do something with the inventory levels or return them
}
Parameters
config
FindConfig<InventoryLevelDTO>select
or relations
, accept the attributes or relations associated with a inventory level.context
SharedContextReturns
Promise<[InventoryLevelDTO[], number]>
listReservationItems
**listReservationItems**(selector, config?, context?): Promise<[[ReservationItemDTO](/references/services/types/ReservationItemDTO)[], number]>
This method is used to retrieve a paginated list of reservation items along with the total count of available reservation items satisfying the provided filters.
Example
To retrieve a list of reservation items using their IDs:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveReservationItems (ids: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [reservationItems, count] = await inventoryModule.listReservationItems({
id: ids
})
// do something with the reservation items or return them
}
To specify relations that should be retrieved within the reservation items:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveReservationItems (ids: string[]) {
const inventoryModule = await initializeInventoryModule({})
const [reservationItems, count] = await inventoryModule.listReservationItems({
id: ids
}, {
relations: ["inventory_item"]
})
// do something with the reservation items or return them
}
By default, only the first 10
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveReservationItems (ids: string[], skip: number, take: number) {
const inventoryModule = await initializeInventoryModule({})
const [reservationItems, count] = await inventoryModule.listReservationItems({
id: ids
}, {
relations: ["inventory_item"],
skip,
take
})
// do something with the reservation items or return them
}
Parameters
config
FindConfig<ReservationItemDTO>select
or relations
, accept the attributes or relations associated with a reservation item.context
SharedContextReturns
Promise<[ReservationItemDTO[], number]>
restoreInventoryItem
**restoreInventoryItem**(inventoryItemId, context?): Promise<void>
This method is used to restore an inventory item or multiple inventory items that were previously deleted using the deleteInventoryItem method.
Example
Parameters
inventoryItemId
string | string[]Requiredcontext
SharedContextReturns
Promise<void>
Promise
Promise<void>RequiredretrieveAvailableQuantity
**retrieveAvailableQuantity**(inventoryItemId, locationIds, context?): Promise<number>
This method is used to retrieve the available quantity of an inventory item within the specified locations.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveAvailableQuantity (
inventoryItemId: string,
locationIds: string[],
) {
const inventoryModule = await initializeInventoryModule({})
const quantity = await inventoryModule.retrieveAvailableQuantity(
inventoryItemId,
locationIds,
)
// do something with the quantity or return it
}
Parameters
inventoryItemId
stringRequiredlocationIds
string[]Requiredcontext
SharedContextReturns
Promise<number>
Promise
Promise<number>RequiredretrieveInventoryItem
**retrieveInventoryItem**(inventoryItemId, config?, context?): Promise<[InventoryItemDTO](/references/services/types/InventoryItemDTO)>
This method is used to retrieve an inventory item by its ID
Example
A simple example that retrieves a inventory item by its ID:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryItem (id: string) {
const inventoryModule = await initializeInventoryModule({})
const inventoryItem = await inventoryModule.retrieveInventoryItem(id)
// do something with the inventory item or return it
}
To specify relations that should be retrieved:
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryItem (id: string) {
const inventoryModule = await initializeInventoryModule({})
const inventoryItem = await inventoryModule.retrieveInventoryItem(id, {
relations: ["inventory_level"]
})
// do something with the inventory item or return it
}
Parameters
inventoryItemId
stringRequiredconfig
FindConfig<InventoryItemDTO>select
or relations
, accept the attributes or relations associated with a inventory item.context
SharedContextReturns
Promise<InventoryItemDTO>
retrieveInventoryLevel
**retrieveInventoryLevel**(inventoryItemId, locationId, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)>
This method is used to retrieve an inventory level for an inventory item and a location.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveInventoryLevel (
inventoryItemId: string,
locationId: string
) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevel = await inventoryModule.retrieveInventoryLevel(
inventoryItemId,
locationId
)
// do something with the inventory level or return it
}
Parameters
inventoryItemId
stringRequiredlocationId
stringRequiredcontext
SharedContextReturns
Promise<InventoryLevelDTO>
retrieveReservationItem
**retrieveReservationItem**(reservationId, context?): Promise<[ReservationItemDTO](/references/services/types/ReservationItemDTO)>
This method is used to retrieve a reservation item by its ID.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveReservationItem (id: string) {
const inventoryModule = await initializeInventoryModule({})
const reservationItem = await inventoryModule.retrieveReservationItem(id)
// do something with the reservation item or return it
}
Parameters
reservationId
stringRequiredcontext
SharedContextReturns
Promise<ReservationItemDTO>
retrieveReservedQuantity
**retrieveReservedQuantity**(inventoryItemId, locationIds, context?): Promise<number>
This method is used to retrieve the reserved quantity of an inventory item within the specified locations.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveReservedQuantity (
inventoryItemId: string,
locationIds: string[],
) {
const inventoryModule = await initializeInventoryModule({})
const quantity = await inventoryModule.retrieveReservedQuantity(
inventoryItemId,
locationIds,
)
// do something with the quantity or return it
}
Parameters
inventoryItemId
stringRequiredlocationIds
string[]Requiredcontext
SharedContextReturns
Promise<number>
Promise
Promise<number>RequiredretrieveStockedQuantity
**retrieveStockedQuantity**(inventoryItemId, locationIds, context?): Promise<number>
This method is used to retrieve the stocked quantity of an inventory item within the specified locations.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function retrieveStockedQuantity (
inventoryItemId: string,
locationIds: string[],
) {
const inventoryModule = await initializeInventoryModule({})
const quantity = await inventoryModule.retrieveStockedQuantity(
inventoryItemId,
locationIds,
)
// do something with the quantity or return it
}
Parameters
inventoryItemId
stringRequiredlocationIds
string[]Requiredcontext
SharedContextReturns
Promise<number>
Promise
Promise<number>RequiredupdateInventoryItem
**updateInventoryItem**(inventoryItemId, input, context?): Promise<[InventoryItemDTO](/references/services/types/InventoryItemDTO)>
This method is used to update an inventory item.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function updateInventoryItem (
inventoryItemId: string,
sku: string
) {
const inventoryModule = await initializeInventoryModule({})
const inventoryItem = await inventoryModule.updateInventoryItem(
inventoryItemId,
{
sku
}
)
// do something with the inventory item or return it
}
Parameters
inventoryItemId
stringRequiredcontext
SharedContextReturns
Promise<InventoryItemDTO>
updateInventoryLevel
**updateInventoryLevel**(inventoryItemId, locationId, update, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)>
This method is used to update an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function updateInventoryLevel (
inventoryItemId: string,
locationId: string,
stockedQuantity: number
) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevel = await inventoryModule.updateInventoryLevels(
inventoryItemId,
locationId,
{
stocked_quantity: stockedQuantity
}
)
// do something with the inventory level or return it
}
Parameters
inventoryItemId
stringRequiredlocationId
stringRequiredcontext
SharedContextReturns
Promise<InventoryLevelDTO>
updateInventoryLevels
**updateInventoryLevels**(updates, context?): Promise<[InventoryLevelDTO](/references/services/types/InventoryLevelDTO)[]>
This method is used to update inventory levels. Each inventory level is identified by the IDs of its associated inventory item and location.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function updateInventoryLevels (items: {
inventory_item_id: string,
location_id: string,
stocked_quantity: number
}[]) {
const inventoryModule = await initializeInventoryModule({})
const inventoryLevels = await inventoryModule.updateInventoryLevels(
items
)
// do something with the inventory levels or return them
}
Parameters
context
SharedContextReturns
Promise<InventoryLevelDTO[]>
updateReservationItem
**updateReservationItem**(reservationItemId, input, context?): Promise<[ReservationItemDTO](/references/services/types/ReservationItemDTO)>
This method is used to update a reservation item.
Example
import {
initialize as initializeInventoryModule,
} from "@medusajs/inventory"
async function updateReservationItem (
reservationItemId: string,
quantity: number
) {
const inventoryModule = await initializeInventoryModule({})
const reservationItem = await inventoryModule.updateReservationItem(
reservationItemId,
{
quantity
}
)
// do something with the reservation item or return it
}
Parameters
reservationItemId
stringRequiredcontext
SharedContextReturns
Promise<ReservationItemDTO>