AdminPriceListResource
This class is used to send requests to Admin Price List API Routes. All its method
are available in the JS Client under the medusa.admin.priceLists property.
All methods in this class require user 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.
Methods
addPrices
Add or update a list of prices in a price list.
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.priceLists
.addPrices(priceListId, {
prices: [
{
amount: 1000,
variant_id,
currency_code: "eur",
},
],
})
.then(({ price_list }) => {
console.log(price_list.id)
})
Parameters
idstringRequiredThe details of prices to add or update.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the price list's details.
create
Create a price list.
Example
Parameters
The price list to create.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the price list details.
delete
Delete a price list and its associated prices.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
deletePrices
Delete a list of prices in a price list
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.priceLists
.deletePrices(priceListId, {
price_ids: [price_id],
})
.then(({ ids, object, deleted }) => {
console.log(ids.length)
})
Parameters
idstringRequiredThe prices to delete.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
deleteProductPrices
Delete all the prices related to a specific product in a price list.
Example
Parameters
priceListIdstringRequiredproductIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
deleteProductsPrices
Delete all the prices associated with multiple products in a price list.
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.priceLists
.deleteProductsPrices(priceListId, {
product_ids: [productId1, productId2],
})
.then(({ ids, object, deleted }) => {
console.log(ids.length)
})
Parameters
priceListIdstringRequiredThe products whose prices should be deleted.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
deleteVariantPrices
Delete all the prices related to a specific product variant in a price list.
Example
Parameters
priceListIdstringRequiredvariantIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
list
Retrieve 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:
To specify relations that should be retrieved within the price lists:
By default, only the first 10 records are retrieved. You can control pagination by specifying the limit and offset properties:
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.priceLists
.list({
expand: "prices",
limit,
offset,
})
.then(({ price_lists, limit, offset, count }) => {
console.log(price_lists.length)
})
Parameters
Filters and pagination configurations to apply on the retrieved price lists.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the list of price lists with pagination fields.
listProducts
Retrieve 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:
To specify relations that should be retrieved within the products:
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.priceLists
.listProducts(priceListId, {
expand: "variants",
})
.then(({ products, limit, offset, count }) => {
console.log(products.length)
})
By default, only the first 50 records are retrieved. You can control pagination by specifying the limit and offset properties:
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.priceLists
.listProducts(priceListId, {
expand: "variants",
limit,
offset,
})
.then(({ products, limit, offset, count }) => {
console.log(products.length)
})
Parameters
idstringRequiredFilters and pagination configurations applied on the retrieved products.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the list of products with pagination fields.
retrieve
Retrieve a price list's details.
Example
Parameters
idstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the price list details.
update
Update a price list's details.
Example
Parameters
idstringRequiredThe attributes to update in the price list.
customHeadersRecord<string, any>RequiredDefault: {}