medusajs/medusa · error · MedusaError
Role with id: ${req.params.id} not found
Error message
Role with id: ${req.params.id} not found What it means
Thrown by GET /admin/rbac/roles/:id when the RBAC role query returns an empty array. The role is fetched by id with the requested fields; a missing role triggers NOT_FOUND.
Source
Thrown at packages/medusa/src/api/admin/rbac/roles/[id]/route.ts:34
/**
* @ignore
* @featureFlag rbac
*/
export const GET = async (
req: AuthenticatedMedusaRequest,
res: MedusaResponse
) => {
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
const { data: roles } = await query.graph({
entity: "rbac_role",
filters: { id: req.params.id },
fields: req.queryConfig.fields,
})
const role = roles[0]
if (!role) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Role with id: ${req.params.id} not found`
)
}
res.status(200).json({ role })
}
/**
* @ignore
* @featureFlag rbac
*/
export const POST = async (
req: AuthenticatedMedusaRequest<AdminUpdateRbacRoleType>,
res: MedusaResponse
) => {
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
const { data: existing } = await query.graph({View on GitHub (pinned to 5e06e544a2)
Solutions
- List roles (GET /admin/rbac/roles) and use current ids
- If a role was deleted but still referenced, either recreate it or remove the references
- Provisioning scripts should check role existence (or create-if-missing) before assigning
Example fix
// before
const { role } = await sdk.client.fetch(`/admin/rbac/roles/${id}`)
// after
const { roles } = await sdk.client.fetch("/admin/rbac/roles")
const role = roles.find((r) => r.id === id)
if (!role) throw new Error(`Role ${id} no longer exists`) Defensive patterns
Strategy: validation
Validate before calling
const { roles } = await sdk.client.fetch("/admin/rbac/roles")
if (!roles.some((r) => r.id === roleId)) throw new Error(`Role ${roleId} not found`) Type guard
const isRole = (v: unknown): v is { id: string } & Record<string, unknown> =>
!!v && typeof v === "object" && "id" in v Try / catch
try {
return await getRole(id)
} catch (e: any) {
if (e.statusCode === 404) { refreshRoles(); return null }
throw e
} Prevention
- Provisioning scripts: check-or-create roles before assigning
- Refresh role pickers after role deletions
- Remove references to deleted roles from user assignment flows
When it happens
Trigger: Calling GET /admin/rbac/roles/role_123 for a role id that was deleted or never existed.
Common situations: Role pickers holding stale role lists after roles were deleted/renamed, user-assignment flows referencing removed roles, or wrong-environment ids in provisioning 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
- Policy with id: ${req.params.id} not found
- Policy with id "${req.params.id}" not found
- Invite with id: ${id} was not found
- Price list with id: ${id} was not found
- Product category with id: ${req.params.id} was not found
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/dc22808f0691689f.
Report an issue: GitHub.