AdminSalesChannelsResource
This class is used to send requests to Admin Sales Channel API Routes. All its method
are available in the JS Client under the medusa.admin.salesChannels property.
All methods in this class require user authentication.
A sales channel indicates a channel where products can be sold in. For example, a webshop or a mobile app. Admins can manage sales channels and the products available in them.
Related Guide: How to manage sales channels.
Methods
addLocation
Associate a stock location with a sales channel.
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.salesChannels
.addLocation(salesChannelId, {
location_id: "loc_123",
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})
Parameters
salesChannelIdstringRequiredThe stock location to associate with the sales channel.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
addProducts
Add a list of products to a sales channel.
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.salesChannels
.addProducts(salesChannelId, {
product_ids: [
{
id: productId,
},
],
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})
Parameters
salesChannelIdstringRequiredThe products to add to the sales channel.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
create
Create a sales channel.
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.salesChannels
.create({
name: "App",
description: "Mobile app",
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})
Parameters
The sales channel to create.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
delete
Delete a sales channel. Associated products, stock locations, and other resources are not deleted.
Example
Parameters
salesChannelIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation's details.
list
Retrieve a list of sales channels. The sales channels can be filtered by fields such as q or name passed in the query parameter. The sales channels can also be sorted or paginated.
Example
To list sales channels:
To specify relations that should be retrieved within the sales channels:
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.salesChannels
.list({
expand: "locations",
})
.then(({ sales_channels, limit, offset, count }) => {
console.log(sales_channels.length)
})
By default, only the first 20 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.salesChannels
.list({
expand: "locations",
limit,
offset,
})
.then(({ sales_channels, limit, offset, count }) => {
console.log(sales_channels.length)
})
Parameters
Filters and pagination configurations applied on the retrieved sales channels.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the list of sales channels with pagination fields.
removeLocation
Remove a stock location from a sales channel. This only removes the association between the stock location and the sales channel. It does not delete the stock location.
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.salesChannels
.removeLocation(salesChannelId, {
location_id: "loc_id",
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})
Parameters
salesChannelIdstringRequiredThe stock location to remove from the sales channel.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
removeProducts
Remove a list of products from a sales channel. This doesn't delete the product. It only removes the association between the product and the sales channel.
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.salesChannels
.removeProducts(salesChannelId, {
product_ids: [
{
id: productId,
},
],
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})
Parameters
salesChannelIdstringRequiredThe products to remove from the sales channel.
customHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
retrieve
Retrieve a sales channel's details.
Example
Parameters
salesChannelIdstringRequiredcustomHeadersRecord<string, any>RequiredDefault: {}
Returns
Resolves to the sales channel's details.
update
Update a sales channel's details.
Example
Parameters
salesChannelIdstringRequiredThe attributes to update in the sales channel.
customHeadersRecord<string, any>RequiredDefault: {}