Inventory Items
Queries and Mutations listed here are used to send requests to the Admin Inventory Item API Routes. To use these hooks, make sure to install the @medusajs/inventory module in your Medusa backend.
All hooks listed 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.
Mutations
useAdminCreateInventoryItem
This hook creates an Inventory Item for a product variant.
Example
import React from "react"
import { useAdminCreateInventoryItem } from "medusa-react"
const CreateInventoryItem = () => {
const createInventoryItem = useAdminCreateInventoryItem()
// ...
const handleCreate = (variantId: string) => {
createInventoryItem.mutate({
variant_id: variantId,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default CreateInventoryItem
Mutation Function Parameters
The details of the inventory item to create.
Mutation Function Returned Data
The inventory item's details.
useAdminUpdateInventoryItem
This hook updates an Inventory Item's details.
Example
import React from "react"
import { useAdminUpdateInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateInventoryItem = useAdminUpdateInventoryItem(
inventoryItemId
)
// ...
const handleUpdate = (origin_country: string) => {
updateInventoryItem.mutate({
origin_country,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.origin_country)
}
})
}
// ...
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredMutation Function Parameters
The attributes to update in an inventory item.
Mutation Function Returned Data
The inventory item's details.
useAdminDeleteInventoryItem
This hook deletes an Inventory Item. This does not delete the associated product variant.
Example
import React from "react"
import { useAdminDeleteInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteInventoryItem = useAdminDeleteInventoryItem(
inventoryItemId
)
// ...
const handleDelete = () => {
deleteInventoryItem.mutate()
}
// ...
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredMutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.useAdminUpdateLocationLevel
This hook updates a location level's details for a given inventory item.
Example
import React from "react"
import { useAdminUpdateLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const updateLocationLevel = useAdminUpdateLocationLevel(
inventoryItemId
)
// ...
const handleUpdate = (
stockLocationId: string,
stockedQuantity: number
) => {
updateLocationLevel.mutate({
stockLocationId,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredMutation Function Parameters
Mutation Function Returned Data
The inventory item's details.
useAdminDeleteLocationLevel
This hook deletes a location level of an Inventory Item.
Example
import React from "react"
import { useAdminDeleteLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const deleteLocationLevel = useAdminDeleteLocationLevel(
inventoryItemId
)
// ...
const handleDelete = (
locationId: string
) => {
deleteLocationLevel.mutate(locationId)
}
// ...
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredMutation Function Parameters
string
stringRequiredMutation Function Returned Data
The inventory item's details.
useAdminCreateLocationLevel
This hook creates a Location Level for a given Inventory Item.
Example
import React from "react"
import { useAdminCreateLocationLevel } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const createLocationLevel = useAdminCreateLocationLevel(
inventoryItemId
)
// ...
const handleCreateLocationLevel = (
locationId: string,
stockedQuantity: number
) => {
createLocationLevel.mutate({
location_id: locationId,
stocked_quantity: stockedQuantity,
}, {
onSuccess: ({ inventory_item }) => {
console.log(inventory_item.id)
}
})
}
// ...
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredMutation Function Parameters
The details of the location level to create.
Mutation Function Returned Data
The inventory item's details.
Queries
useAdminInventoryItems
This hook retrieves 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
To list inventory items:
import React from "react"
import { useAdminInventoryItems } from "medusa-react"
function InventoryItems() {
const {
inventory_items,
isLoading
} = useAdminInventoryItems()
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_items && !inventory_items.length && (
<span>No Items</span>
)}
{inventory_items && inventory_items.length > 0 && (
<ul>
{inventory_items.map(
(item) => (
<li key={item.id}>{item.id}</li>
)
)}
</ul>
)}
</div>
)
}
export default InventoryItems
By default, only the first 20
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import React from "react"
import { useAdminInventoryItems } from "medusa-react"
function InventoryItems() {
const {
inventory_items,
limit,
offset,
isLoading
} = useAdminInventoryItems({
limit: 10,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_items && !inventory_items.length && (
<span>No Items</span>
)}
{inventory_items && inventory_items.length > 0 && (
<ul>
{inventory_items.map(
(item) => (
<li key={item.id}>{item.id}</li>
)
)}
</ul>
)}
</div>
)
}
export default InventoryItems
Hook Parameters
Filters and pagination configurations applied on the retrieved inventory items.
Query Returned Data
limit
numberRequiredoffset
numberRequiredcount
numberRequiredan array of Inventory Item details
useAdminInventoryItem
This hook retrieves an Inventory Item's details.
Example
import React from "react"
import { useAdminInventoryItem } from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading
} = useAdminInventoryItem(inventoryItemId)
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_item && (
<span>{inventory_item.sku}</span>
)}
</div>
)
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredConfigurations applied on the retrieved inventory item.
Query Returned Data
Inventory Item details
useAdminInventoryItemLocationLevels
This hook retrieves 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 React from "react"
import {
useAdminInventoryItemLocationLevels,
} from "medusa-react"
type Props = {
inventoryItemId: string
}
const InventoryItem = ({ inventoryItemId }: Props) => {
const {
inventory_item,
isLoading,
} = useAdminInventoryItemLocationLevels(inventoryItemId)
return (
<div>
{isLoading && <span>Loading...</span>}
{inventory_item && (
<ul>
{inventory_item.location_levels.map((level) => (
<span key={level.id}>{level.stocked_quantity}</span>
))}
</ul>
)}
</div>
)
}
export default InventoryItem
Hook Parameters
inventoryItemId
stringRequiredFilters to apply on the retrieved location levels.
Query Returned Data
inventory_item
objectRequiredAn inventory item's ID and associated location levels.
inventory_item
objectRequired