{"record":{"id":"0d9591453098aa80","repo":"medusajs/medusa","slug":"user-with-id-userid-not-found","errorCode":null,"errorMessage":"User with id \"${userId}\" not found","messagePattern":"User with id \"(.+?)\" not found","errorType":"exception","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/medusa/src/api/admin/users/[id]/roles/route.ts","lineNumber":66,"sourceCode":"  req: AuthenticatedMedusaRequest<\n    HttpTypes.AdminAssignUserRoles\n  >,\n  res: MedusaResponse\n) => {\n  const userId = req.params.id\n  const { roles } = req.validatedBody\n  const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)\n\n  const {\n    data: [user],\n  } = await query.graph({\n    entity: \"user\",\n    fields: [\"id\"],\n    filters: { id: userId },\n  })\n\n  if (!user) {\n    throw new MedusaError(\n      MedusaError.Types.NOT_FOUND,\n      `User with id \"${userId}\" not found`\n    )\n  }\n\n  await assignUserRolesWorkflow(req.scope).run({\n    input: {\n      actor_id: req.auth_context.actor_id,\n      actor: req.auth_context.actor_type,\n      user_id: userId,\n      role_ids: roles,\n    },\n  })\n\n  const { data: links } = await query.graph({\n    entity: \"user_rbac_role\",\n    fields: [\"rbac_role.*\"],\n    filters: { user_id: userId },","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/medusa/src/api/admin/users/[id]/roles/route.ts#L48-L84","documentation":"Thrown by POST /admin/users/:id/roles when the workflow target user does not exist. The route first queries the user entity by id and throws a NOT_FOUND MedusaError before invoking assignUserRolesWorkflow.","triggerScenarios":"POST /admin/users/{id}/roles with a user id that was deleted, never existed, or contains a typo; also when soft-deleted users are filtered out by the remote query.","commonSituations":"Stale user id cached in the admin UI, deleting a user in another tab then assigning roles, or copying ids between environments (staging vs production).","solutions":["Verify the user exists: GET /admin/users/{id}","If soft-deleted, restore the user before assigning roles","Copy the exact id from the users list endpoint"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const { users } = await medusa.admin.users.list({ q: userId })\nif (!users.some(u => u.id === userId)) return skip()","typeGuard":"const isExistingUser = (u: {id: string} | undefined): u is {id: string} => !!u","tryCatchPattern":"try { await assignUserRoles(...) } catch (e) { if (e.type === 'not_found') refreshUserList(); else throw e }","preventionTips":["Resolve user ids from a fresh users list at action time","Handle 404 by refetching the user list"],"tags":["admin","users","roles","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}