medusajs/medusa · error · MedusaError
Requested sales channel is not part of the publishable key
Error message
Requested sales channel is not part of the publishable key
What it means
Thrown by the store product middleware when a request supplies sales_channel_id filter values that are not among the sales channels attached to the publishable key used on the request. Medusa scopes store requests to the publishable key's sales channels, so asking for products in any other channel is rejected as invalid data. It is raised before the query runs, in transformAndValidateSalesChannelIds.
Source
Thrown at packages/medusa/src/api/utils/middlewares/products/filter-by-valid-sales-channels.ts:32
req.publishable_key_context
let { sales_channel_id: idsFromRequest = [] } = req.validatedQuery as {
sales_channel_id: string | string[]
}
idsFromRequest = Array.isArray(idsFromRequest)
? idsFromRequest
: [idsFromRequest]
// If all sales channel ids are not in the publishable key, we throw an error
if (idsFromRequest.length) {
const uniqueInParams = arrayDifference(
idsFromRequest,
idsFromPublishableKey
)
if (uniqueInParams.length) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Requested sales channel is not part of the publishable key`
)
}
return idsFromRequest
}
if (idsFromPublishableKey?.length) {
return idsFromPublishableKey
}
return []
}
// Selection of sales channels happens in the following priority:
// - If a publishable API key is passed, we take the sales channels attached to it and filter them down based on the query params
// - If a sales channel id is passed through query params, we use thatView on GitHub (pinned to 5e06e544a2)
Solutions
- Verify the sales channel ids in the request are attached to the publishable key: check the publishable key's sales_channels in Admin (Settings > Publishable API Keys) or via /admin/api-keys
- Remove the sales_channel_id filter and let the publishable key's channels scope the query
- If the channel genuinely should be accessible, add it to the publishable key in the admin and retry
Example fix
// before GET /store/products?sales_channel_id=sc_other_env x-publishable-api-key: pk_live_... // after GET /store/products?sales_channel_id=sc_linked_channel x-publishable-api-key: pk_live_...
Defensive patterns
Strategy: validation
Validate before calling
// before the request, compare desired channel ids with the key's channels
const keyChannels = await fetch('/store/sales-channels', {
headers: { 'x-publishable-api-key': PK },
}).then(r => r.json()).then(d => d.sales_channels.map(c => c.id))
const wanted = ['sc_x']
const valid = wanted.every(id => keyChannels.includes(id))
if (!valid) throw new Error('sales channel not in publishable key') Type guard
const isValidSalesChannelId = ( id: string, keyChannelIds: string[] ): boolean => keyChannelIds.includes(id)
Try / catch
try {
await sdk.store.product.list({ sales_channel_id: ids })
} catch (e) {
if (e.type === 'invalid_data' && /not part of the publishable key/.test(e.message)) {
// refresh channel list, drop the filter, or surface a config error
}
throw e
} Prevention
- Fetch and cache the publishable key's sales channels at storefront startup and validate filters against them
- Never hardcode sales channel ids across environments; resolve them per environment
When it happens
Trigger: Calling GET /store/products?sales_channel_id=sc_xxx (single value or comma/array list) where sc_xxx is not linked to the publishable key sent in the x-publishable-api-key header. Any store product/variant endpoint that goes through filterByValidSalesChannels.
Common situations: Copy-pasting a sales channel id from another environment (staging vs prod), using a newly created sales channel without attaching it to the publishable key, or sending the admin sales channel id instead of the store one.
Related errors
- Publishable key needs to have a sales channel configured
- Inventory availability cannot be calculated in the given con
- invalid_data
- NOT_ALLOWED
- --paths must be a directory - ${additionalPath}
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/40d259c63ebe115c.
Report an issue: GitHub.