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 that

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. 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
  2. Remove the sales_channel_id filter and let the publishable key's channels scope the query
  3. 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

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


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/40d259c63ebe115c. Report an issue: GitHub.