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
stringRequiredThe inventory item's ID.
Mutation 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.