Skip to main content
Skip to main content

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

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.retrieve(salesChannelId)
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})

Parameters

salesChannelIdstringRequired
The sales channel's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
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>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
Resolves to the sales channel's details.

update

Update a sales channel'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.salesChannels.update(salesChannelId, {
name: "App"
})
.then(({ sales_channel }) => {
console.log(sales_channel.id)
})

Parameters

salesChannelIdstringRequired
The sales channel's ID.
The attributes to update in the sales channel.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
Resolves to the sales channel'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:

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

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

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

Default: {}

Filters and pagination configurations applied on the retrieved sales channels.

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsListRes>Required
Resolves to the list of sales channels with pagination fields.

delete

Delete a sales channel. Associated products, stock locations, and other resources are not deleted.

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

Parameters

salesChannelIdstringRequired
The sales channel's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation'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

salesChannelIdstringRequired
The sales channel's ID.
The products to remove from the sales channel.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

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

salesChannelIdstringRequired
The sales channel's ID.
The products to add to the sales channel.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
Resolves to the sales channel's details.

addLocation

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

salesChannelIdstringRequired
The sales channel's ID.
The stock location to associate with the sales channel.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
Resolves to the sales channel's details.

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

salesChannelIdstringRequired
The sales channel's ID.
The stock location to remove from the sales channel.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminSalesChannelsRes>Required
Resolves to the sales channel's details.
Was this section helpful?