Price Lists
Queries and Mutations listed here are used to send requests to the Admin Price List API Routes.
All hooks listed require authentication.
A price list are special prices applied to products based on a set of conditions, such as customer group.
Related Guide: How to manage price lists.
Mutations
useAdminCreatePriceList
This hook creates a price list.
Example
import React from "react"
import {
PriceListStatus,
PriceListType,
} from "@medusajs/medusa"
import { useAdminCreatePriceList } from "medusa-react"
type CreateData = {
name: string
description: string
type: PriceListType
status: PriceListStatus
prices: {
amount: number
variant_id: string
currency_code: string
max_quantity: number
}[]
}
const CreatePriceList = () => {
const createPriceList = useAdminCreatePriceList()
// ...
const handleCreate = (
data: CreateData
) => {
createPriceList.mutate(data, {
onSuccess: ({ price_list }) => {
console.log(price_list.id)
}
})
}
// ...
}
export default CreatePriceList
Mutation Function Parameters
The details of the price list to create.
Mutation Function Returned Data
The price list's details.
useAdminUpdatePriceList
This hook updates a price list's details.
Example
import React from "react"
import { useAdminUpdatePriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const updatePriceList = useAdminUpdatePriceList(priceListId)
// ...
const handleUpdate = (
endsAt: Date
) => {
updatePriceList.mutate({
ends_at: endsAt,
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.ends_at)
}
})
}
// ...
}
export default PriceList
Hook Parameters
id
stringRequiredMutation Function Parameters
The details to update of the payment collection.
Mutation Function Returned Data
The price list's details.
useAdminDeletePriceList
This hook deletes a price list and its associated prices.
Example
import React from "react"
import { useAdminDeletePriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deletePriceList = useAdminDeletePriceList(priceListId)
// ...
const handleDelete = () => {
deletePriceList.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default PriceList
Hook Parameters
id
stringRequiredMutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.useAdminCreatePriceListPrices
This hook adds or updates a list of prices in a price list.
Example
import React from "react"
import { useAdminCreatePriceListPrices } from "medusa-react"
type PriceData = {
amount: number
variant_id: string
currency_code: string
}
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const addPrices = useAdminCreatePriceListPrices(priceListId)
// ...
const handleAddPrices = (prices: PriceData[]) => {
addPrices.mutate({
prices
}, {
onSuccess: ({ price_list }) => {
console.log(price_list.prices)
}
})
}
// ...
}
export default PriceList
Hook Parameters
id
stringRequiredMutation Function Parameters
The details of the prices to add.
Mutation Function Returned Data
The price list's details.
useAdminDeletePriceListPrices
This hook deletes a list of prices in a price list.
Example
import React from "react"
import { useAdminDeletePriceListPrices } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deletePrices = useAdminDeletePriceListPrices(priceListId)
// ...
const handleDeletePrices = (priceIds: string[]) => {
deletePrices.mutate({
price_ids: priceIds
}, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
Hook Parameters
id
stringRequiredMutation Function Parameters
The details of the prices to delete.
Mutation Function Returned Data
The details of deleting a price list.
useAdminDeletePriceListProductsPrices
This hook deletes all the prices associated with multiple products in a price list.
Example
import React from "react"
import { useAdminDeletePriceListProductsPrices } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const deleteProductsPrices = useAdminDeletePriceListProductsPrices(
priceListId
)
// ...
const handleDeleteProductsPrices = (productIds: string[]) => {
deleteProductsPrices.mutate({
product_ids: productIds
}, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceList
Hook Parameters
id
stringRequiredMutation Function Parameters
AdminDeletePriceListsPriceListProductsPricesBatchReq
AdminDeletePriceListsPriceListProductsPricesBatchReqRequiredThe details of the products' prices to delete.
AdminDeletePriceListsPriceListProductsPricesBatchReq
AdminDeletePriceListsPriceListProductsPricesBatchReqRequiredMutation Function Returned Data
The details of deleting a price list.
useAdminDeletePriceListProductPrices
This hook deletes all the prices related to a specific product in a price list.
Example
import React from "react"
import {
useAdminDeletePriceListProductPrices
} from "medusa-react"
type Props = {
priceListId: string
productId: string
}
const PriceListProduct = ({
priceListId,
productId
}: Props) => {
const deleteProductPrices = useAdminDeletePriceListProductPrices(
priceListId,
productId
)
// ...
const handleDeleteProductPrices = () => {
deleteProductPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceListProduct
Hook Parameters
id
stringRequiredproductId
stringRequiredMutation Function Returned Data
The details of deleting a price list.
useAdminDeletePriceListVariantPrices
This hook deletes all the prices related to a specific product variant in a price list.
Example
import React from "react"
import {
useAdminDeletePriceListVariantPrices
} from "medusa-react"
type Props = {
priceListId: string
variantId: string
}
const PriceListVariant = ({
priceListId,
variantId
}: Props) => {
const deleteVariantPrices = useAdminDeletePriceListVariantPrices(
priceListId,
variantId
)
// ...
const handleDeleteVariantPrices = () => {
deleteVariantPrices.mutate(void 0, {
onSuccess: ({ ids, deleted, object }) => {
console.log(ids)
}
})
}
// ...
}
export default PriceListVariant
Hook Parameters
id
stringRequiredvariantId
stringRequiredMutation Function Returned Data
The details of deleting a price list.
Queries
useAdminPriceLists
This hook retrieves a list of price lists. The price lists can be filtered by fields such as q
or status
passed
in the query
parameter. The price lists can also be sorted or paginated.
Example
To list price lists:
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const { price_lists, isLoading } = useAdminPriceLists()
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
To specify relations that should be retrieved within the price lists:
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const { price_lists, isLoading } = useAdminPriceLists({
expand: "prices"
})
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
By default, only the first 10
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import React from "react"
import { useAdminPriceLists } from "medusa-react"
const PriceLists = () => {
const {
price_lists,
limit,
offset,
isLoading
} = useAdminPriceLists({
expand: "prices",
limit: 20,
offset: 0
})
return (
<div>
{isLoading && <span>Loading...</span>}
{price_lists && !price_lists.length && (
<span>No Price Lists</span>
)}
{price_lists && price_lists.length > 0 && (
<ul>
{price_lists.map((price_list) => (
<li key={price_list.id}>{price_list.name}</li>
))}
</ul>
)}
</div>
)
}
export default PriceLists
Hook Parameters
Filters and pagination configurations to apply on the retrieved price lists.
Query Returned Data
limit
numberRequiredoffset
numberRequiredcount
numberRequiredAn array of price lists details.
useAdminPriceListProducts
This hook retrieves a price list's products. The products can be filtered by fields such as q
or status
passed in the query
parameter. The products can also be sorted or paginated.
Example
To list products in a price list:
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const { products, isLoading } = useAdminPriceListProducts(
priceListId
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
To specify relations that should be retrieved within the products:
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const { products, isLoading } = useAdminPriceListProducts(
priceListId,
{
expand: "variants"
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
By default, only the first 50
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
import React from "react"
import { useAdminPriceListProducts } from "medusa-react"
type Props = {
priceListId: string
}
const PriceListProducts = ({
priceListId
}: Props) => {
const {
products,
limit,
offset,
isLoading
} = useAdminPriceListProducts(
priceListId,
{
expand: "variants",
limit: 20,
offset: 0
}
)
return (
<div>
{isLoading && <span>Loading...</span>}
{products && !products.length && (
<span>No Price Lists</span>
)}
{products && products.length > 0 && (
<ul>
{products.map((product) => (
<li key={product.id}>{product.title}</li>
))}
</ul>
)}
</div>
)
}
export default PriceListProducts
Hook Parameters
id
stringRequiredFilters and pagination configurations applied on the retrieved products.
Query Returned Data
limit
numberRequiredoffset
numberRequiredcount
numberRequireduseAdminPriceList
This hook retrieves a price list's details.
Example
import React from "react"
import { useAdminPriceList } from "medusa-react"
type Props = {
priceListId: string
}
const PriceList = ({
priceListId
}: Props) => {
const {
price_list,
isLoading,
} = useAdminPriceList(priceListId)
return (
<div>
{isLoading && <span>Loading...</span>}
{price_list && <span>{price_list.name}</span>}
</div>
)
}
export default PriceList
Hook Parameters
id
stringRequired