Skip to main content
Skip to main content

AdminInventoryItemsResource

This class is used to send requests to Admin Inventory Item API Routes. To use these API Routes, make sure to install the @medusajs/inventory module in your Medusa backend. All its method are available in the JS Client under the medusa.admin.inventoryItems property.

All methods in this class require user authentication.

Inventory items, provided by the Inventory Module, can be used to manage the inventory of saleable items in your store.

Related Guide: How to manage inventory items.

Methods

create

Create an Inventory Item for a product variant.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.create({
variant_id: "variant_123",
})
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

The inventory item to create.
Configurations to apply on the retrieved inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
The inventory item's details.

createLocationLevel

Create a Location Level for a given Inventory Item.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.createLocationLevel(inventoryItemId, {
location_id: "sloc_123",
stocked_quantity: 10,
})
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item that the location level belongs to.
The location level to create.
Configurations to apply on the returned inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
the inventory item's details.

delete

Delete an Inventory Item. This does not delete the associated product variant.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.delete(inventoryItemId)
.then(({ id, object, deleted }) => {
console.log(id)
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
The deletion operation's details.

deleteLocationLevel

Delete a location level of an Inventory Item.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.deleteLocationLevel(inventoryItemId, locationId)
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item.
locationIdstringRequired
The ID of the location level to delete.
Configurations to apply on the returned inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
the inventory item's details.

list

Retrieve a list of inventory items. The inventory items can be filtered by fields such as q or location_id passed in the query parameter. The inventory items can also be paginated.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.list()
.then(({ inventory_items, count, offset, limit }) => {
console.log(inventory_items.length);
})

Parameters

Filters and pagination configurations applied on the retrieved inventory items.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsListWithVariantsAndLocationLevelsRes>Required
The list of inventory items with pagination fields.

listLocationLevels

Retrieve a list of inventory levels of an inventory item. The inventory levels can be filtered by fields such as location_id passed in the query parameter.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.listLocationLevels(inventoryItemId)
.then(({ inventory_item }) => {
console.log(inventory_item.location_levels);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item that the location levels belong to.
Filters to apply on the retrieved location levels.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsLocationLevelsRes>Required
The inventory item's details and list of location levels.

retrieve

Retrieve an Inventory Item's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.retrieve(inventoryItemId)
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item.
Configurations applied on the retrieved inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
The inventory item's details.

update

Update an Inventory Item's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.update(inventoryItemId, {
origin_country: "US",
})
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item.
The attributes to update in the inventory item.
Configurations to apply on the retrieved inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
The inventory item's details.

updateLocationLevel

Update a location level's details for a given inventory item.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.inventoryItems.updateLocationLevel(inventoryItemId, locationId, {
stocked_quantity: 15,
})
.then(({ inventory_item }) => {
console.log(inventory_item.id);
})

Parameters

inventoryItemIdstringRequired
The ID of the inventory item that the location level belongs to.
locationIdstringRequired
The ID of the location level to update.
The attributes to update in the location level.
Configurations to apply on the returned inventory item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminInventoryItemsRes>Required
the inventory item's details.
Was this section helpful?