{"record":{"id":"a58f5d03439022e2","repo":"medusajs/medusa","slug":"region-with-id-req-filterablefields-region-id-n","errorCode":null,"errorMessage":"Region with id ${req.filterableFields.region_id} not found when populating the pricing context","messagePattern":"Region with id (.+?) not found when populating the pricing context","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/medusa/src/api/utils/middlewares/products/set-pricing-context.ts","lineNumber":43,"sourceCode":"      return next()\n    }\n\n    // We validate the region ID in the previous middleware\n    const region = await refetchEntity({\n      entity: \"region\",\n      idOrFilter: req.filterableFields.region_id!,\n      scope: req.scope,\n      fields: [\"id\", \"currency_code\"],\n      options: {\n        cache: {\n          enable: true,\n        },\n      },\n    })\n\n    if (!region) {\n      try {\n        throw new MedusaError(\n          MedusaError.Types.INVALID_DATA,\n          `Region with id ${req.filterableFields.region_id} not found when populating the pricing context`\n        )\n      } catch (e) {\n        return next(e)\n      }\n    }\n\n    const pricingContext: MedusaPricingContext = {\n      region_id: region.id,\n      currency_code: region.currency_code,\n    }\n\n    // Find all the customer groups the customer is a part of and set\n    if (req.auth_context?.actor_id) {\n      const { data: customerGroups } = await refetchEntities({\n        entity: \"customer_group\",\n        idOrFilter: { customers: { id: req.auth_context.actor_id } },","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/medusa/src/api/utils/middlewares/products/set-pricing-context.ts#L25-L61","documentation":"Thrown by setPricingContext when the region_id supplied on the request (req.filterableFields.region_id) does not correspond to an existing region. The middleware fetches the region to build pricing context (currency, tax rates) and refuses to continue with an unknown region.","triggerScenarios":"GET /store/products?region_id=reg_does_not_exist (deleted region, id from another environment, or a typo). Any store request that populates filterableFields.region_id with a stale value.","commonSituations":"Frontend caching an old region id after regions were re-created; copying ids across environments; region soft-deleted while the storefront still references it.","solutions":["List valid regions via GET /store/regions and use a current id","If regions were re-seeded, clear cached region ids in the storefront (localStorage/cookies)","Pass no region_id and rely on the store's default region instead"],"exampleFix":"// before\nGET /store/products?region_id=reg_stale\n\n// after\nGET /store/products?region_id=reg_current","handlingStrategy":"validation","validationCode":"const { regions } = await sdk.store.region.list()\nconst regionId = regions.find(r => r.id === requestedId)?.id\nif (!regionId) {\n  requestedId = regions[0]?.id // or re-prompt\n}\nconst products = await sdk.store.product.list({ region_id: regionId })","typeGuard":"const isExistingRegionId = (id: string, regions: {id: string}[]): boolean =>\n  regions.some(r => r.id === id)","tryCatchPattern":"try {\n  await sdk.store.product.list({ region_id: id })\n} catch (e) {\n  if (e.type === 'invalid_data' && /not found when populating the pricing context/.test(e.message)) {\n    // refresh cached regions and retry\n  }\n  throw e\n}","preventionTips":["Refresh cached region ids on app start instead of persisting them indefinitely","When deleting/recreating regions, version-bump the client's region cache"],"tags":["region","pricing","store-api","not-found"],"backgroundTag":"invalid-region-id","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}