Skip to main content
Skip to main content

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

create

Create a price list.

Example

medusa.admin.priceLists.create({
name: "New Price List",
description: "A new price list",
type: PriceListType.SALE,
prices: [
{
amount: 1000,
variant_id,
currency_code: "eur"
}
]
})
.then(({ price_list }) => {
console.log(price_list.id);
})

Parameters

The price list to create.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListRes>Required
Resolves to the price list details.

update

Update a price list'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.priceLists.update(priceListId, {
name: "New Price List"
})
.then(({ price_list }) => {
console.log(price_list.id);
})

Parameters

idstringRequired
The ID of the price list.
The attributes to update in the price list.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListRes>Required
Resolves to the price list details.

delete

Delete a price list and its associated prices.

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.delete(priceListId)
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters

idstringRequired
The ID of the price list.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

retrieve

Retrieve a price list'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.priceLists.retrieve(priceListId)
.then(({ price_list }) => {
console.log(price_list.id);
})

Parameters

idstringRequired
The ID of the price list.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListRes>Required
Resolves to the price list 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:

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()
.then(({ price_lists, limit, offset, count }) => {
console.log(price_lists.length);
})

To specify relations that should be retrieved within the price lists:

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"
})
.then(({ price_lists, limit, offset, count }) => {
console.log(price_lists.length);
})

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

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Filters and pagination configurations to apply on the retrieved price lists.

Returns

ResponsePromiseResponsePromise<AdminPriceListsListRes>Required
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:

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)
.then(({ products, limit, offset, count }) => {
console.log(products.length);
})

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

idstringRequired
The ID of the price list.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Filters and pagination configurations applied on the retrieved products.

Returns

ResponsePromiseResponsePromise<AdminPriceListsProductsListRes>Required
Resolves to the list of products with pagination fields.

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

idstringRequired
The ID of the price list.
The details of prices to add or update.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListRes>Required
Resolves to the price list'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

idstringRequired
The ID of the price list.
The prices to delete.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListDeleteBatchRes>Required
Resolves to the deletion operation's details.

deleteProductPrices

Delete all the prices related to a specific product 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.deleteProductPrices(priceListId, productId)
.then(({ ids, object, deleted }) => {
console.log(ids.length);
})

Parameters

priceListIdstringRequired
The ID of the price list.
productIdstringRequired
The product's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListDeleteBatchRes>Required
Resolves to the deletion operation's details.

deleteVariantPrices

Delete all the prices related to a specific product variant 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.deleteVariantPrices(priceListId, variantId)
.then(({ ids, object, deleted }) => {
console.log(ids);
})

Parameters

priceListIdstringRequired
The ID of the price list.
variantIdstringRequired
The ID of the product variant.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListDeleteBatchRes>Required
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

priceListIdstringRequired
The ID of the price list.
The products whose prices should be deleted.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPriceListDeleteBatchRes>Required
Resolves to the deletion operation's details.
Was this section helpful?