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
inventoryItemIdstringRequiredlocationIdstringRequiredadjustmentnumberRequiredcontextSharedContextReturns
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
inventoryItemIdstringRequiredlocationIdsstring[]RequiredquantitynumberRequiredcontextSharedContextReturns
Promise<boolean>
PromisePromise<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
contextSharedContextReturns
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
contextSharedContextReturns
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
contextSharedContextReturns
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
contextSharedContextReturns
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
contextSharedContextReturns
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
contextSharedContextReturns
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
inventoryItemIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
locationIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
inventoryItemIdstringRequiredlocationIdstringRequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
reservationItemIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<void>RequireddeleteReservationItemByLocationId
**deleteReservationItemByLocationId**(locationId, context?): Promise<void>
This method deletes reservation item(s) by the ID(s) of associated location(s).
Example
Parameters
locationIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
lineItemIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
configFindConfig<InventoryItemDTO>select or relations, accept the attributes or relations associated with a inventory item.contextSharedContextReturns
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
configFindConfig<InventoryLevelDTO>select or relations, accept the attributes or relations associated with a inventory level.contextSharedContextReturns
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
configFindConfig<ReservationItemDTO>select or relations, accept the attributes or relations associated with a reservation item.contextSharedContextReturns
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
inventoryItemIdstring | string[]RequiredcontextSharedContextReturns
Promise<void>
PromisePromise<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
inventoryItemIdstringRequiredlocationIdsstring[]RequiredcontextSharedContextReturns
Promise<number>
PromisePromise<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
inventoryItemIdstringRequiredconfigFindConfig<InventoryItemDTO>select or relations, accept the attributes or relations associated with a inventory item.contextSharedContextReturns
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
inventoryItemIdstringRequiredlocationIdstringRequiredcontextSharedContextReturns
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
reservationIdstringRequiredcontextSharedContextReturns
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
inventoryItemIdstringRequiredlocationIdsstring[]RequiredcontextSharedContextReturns
Promise<number>
PromisePromise<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
inventoryItemIdstringRequiredlocationIdsstring[]RequiredcontextSharedContextReturns
Promise<number>
PromisePromise<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
inventoryItemIdstringRequiredcontextSharedContextReturns
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
inventoryItemIdstringRequiredlocationIdstringRequiredcontextSharedContextReturns
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
contextSharedContextReturns
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
reservationItemIdstringRequiredcontextSharedContextReturns
Promise<ReservationItemDTO>