medusajs/medusa · error · MedusaError

Publishable key needs to have a sales channel configured

Error message

Publishable key needs to have a sales channel configured

What it means

Thrown by filterByValidSalesChannels when the resolved sales channel list for a store request is empty — the publishable key has no sales channels attached and the request supplied no sales_channel_id either. Medusa cannot scope store product queries without at least one sales channel, so it fails fast with INVALID_DATA.

Source

Thrown at packages/medusa/src/api/utils/middlewares/products/filter-by-valid-sales-channels.ts:57

  }

  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
// - If not, we use the default sales channel for the store
export function filterByValidSalesChannels() {
  return async (req: MedusaStoreRequest, _, next: NextFunction) => {
    const salesChannelIds = transformAndValidateSalesChannelIds(req)

    if (!salesChannelIds.length) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `Publishable key needs to have a sales channel configured`
      )
    }

    req.filterableFields.sales_channel_id = salesChannelIds
    next()
  }
}

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Attach at least one sales channel to the publishable key via Admin > Settings > Publishable API Keys (or /admin/api-keys update with sales_channel_id)
  2. If no default sales channel exists, create one first (Admin > Settings > Sales Channels or the store endpoint)
  3. Pass sales_channel_id explicitly in the request as a temporary workaround

Example fix

// before (key has no channels)
GET /store/products
x-publishable-api-key: pk_empty

// after
// attach sc_default to the key, then
GET /store/products
x-publishable-api-key: pk_with_channel
// or pass one explicitly
GET /store/products?sales_channel_id=sc_default
Defensive patterns

Strategy: validation

Validate before calling

// storefront bootstrap check
const res = await fetch('/store/products?limit=1', {
  headers: { 'x-publishable-api-key': PK },
})
if (res.status === 400) {
  // key misconfigured: alert, or fallback to explicit channel
  url.searchParams.set('sales_channel_id', DEFAULT_SC_ID)
}

Try / catch

try {
  return await sdk.store.product.list()
} catch (e) {
  if (e.type === 'invalid_data' && /sales channel configured/.test(e.message)) {
    return { error: 'publishable-key-misconfigured' }
  }
  throw e
}

Prevention

When it happens

Trigger: Calling any /store/products endpoint with a publishable key that has zero sales channels configured, and no sales_channel_id query parameter as a fallback.

Common situations: Fresh Medusa setup where the seed script wasn't run or the default sales channel wasn't linked to the created publishable key; publishing a storefront key before assigning channels; deleted sales channels leaving the key empty.

Related errors


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