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
retrieve
Retrieve a sales channel's details.
Example
Parameters
salesChannelId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>Requiredcreate
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.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>Requiredupdate
Update a sales channel's details.
Example
Parameters
salesChannelId
stringRequiredThe attributes to update in the sales channel.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>Requiredlist
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
customHeaders
Record<string, any>RequiredDefault: {}
Filters and pagination configurations applied on the retrieved sales channels.
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsListRes>RequiredResolves to the list of sales channels with pagination fields.
ResponsePromise
ResponsePromise<AdminSalesChannelsListRes>Requireddelete
Delete a sales channel. Associated products, stock locations, and other resources are not deleted.
Example
Parameters
salesChannelId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation's details.
ResponsePromise
ResponsePromise<DeleteResponse>RequiredremoveProducts
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
salesChannelId
stringRequiredThe products to remove from the sales channel.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredaddProducts
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
salesChannelId
stringRequiredThe products to add to the sales channel.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredaddLocation
Associate a stock location with a sales channel. It requires the @medusajs/stock-location module to be installed in your Medusa backend.
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
salesChannelId
stringRequiredThe stock location to associate with the sales channel.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredremoveLocation
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
salesChannelId
stringRequiredThe stock location to remove from the sales channel.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>RequiredResolves to the sales channel's details.
ResponsePromise
ResponsePromise<AdminSalesChannelsRes>Required