medusajs/medusa · error · MedusaError

Product category with id: ${req.params.id} was not found

Error message

Product category with id: ${req.params.id} was not found

What it means

Thrown by GET /admin/product-categories/:id when refetchProductCategory returns nothing. The category is fetched through the product category service/query with the requested fields and pagination; an empty result triggers NOT_FOUND.

Source

Thrown at packages/medusa/src/api/admin/product-categories/[id]/route.ts:33

export const GET = async (
  req: AuthenticatedMedusaRequest<
    HttpTypes.AdminProductCategoryListParams
  >,
  res: MedusaResponse<AdminProductCategoryResponse>
) => {
  const {
    data: [category],
  } = await refetchEntities({
    entity: "product_category",
    idOrFilter: { id: req.params.id, ...req.filterableFields },
    scope: req.scope,
    fields: req.queryConfig.fields,
    pagination: req.queryConfig.pagination,
  })

  if (!category) {
    throw new MedusaError(
      MedusaError.Types.NOT_FOUND,
      `Product category with id: ${req.params.id} was not found`
    )
  }

  res.json({ product_category: category })
}

export const POST = async (
  req: AuthenticatedMedusaRequest<
    HttpTypes.AdminUpdateProductCategory,
    HttpTypes.AdminProductCategoryParams
  >,
  res: MedusaResponse<AdminProductCategoryResponse>
) => {
  const { id } = req.params

  await updateProductCategoriesWorkflow(req.scope).run({

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Refresh the category list (GET /admin/product-categories) and use current ids
  2. If products still reference the deleted category, clean up the references and update UI caches
  3. Verify the id comes from the same store/environment

Example fix

// before
const { product_category } = await sdk.admin.productCategory.retrieve(catId)

// after
const { product_categories } = await sdk.admin.productCategory.list({ q: name })
if (!product_categories.some((c) => c.id === catId)) {
  throw new Error(`Category ${catId} no longer exists`)
}
Defensive patterns

Strategy: validation

Validate before calling

const { product_categories } = await sdk.admin.productCategory.list({ id: [catId] })
if (product_categories.length === 0) throw new Error(`Category ${catId} not found`)

Type guard

const isCategory = (v: unknown): v is HttpTypes.AdminProductCategory =>
  !!v && typeof v === "object" && "id" in v && "name" in v

Try / catch

try {
  return await getCategory(catId)
} catch (e: any) {
  if (e.statusCode === 404) { refreshCategoryTree(); return null }
  throw e
}

Prevention

When it happens

Trigger: Requesting a category id that does not exist, was deleted, or is an internal category excluded from the query.

Common situations: UI holding a stale category tree after categories were reorganized/deleted, deleted categories still referenced by products, or wrong-environment ids in scripts.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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