{"record":{"id":"94b1668b56e95952","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-getchatflowbyid-works","errorCode":null,"errorMessage":"Error: chatflowsController.getChatflowById - workspace ${workspaceId} not found!","messagePattern":"Error: chatflowsController\\.getChatflowById - workspace (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":134,"sourceCode":"        const apikey = await apiKeyService.getApiKey(req.params.apikey)\n        if (!apikey) {\n            return res.status(401).send('Unauthorized')\n        }\n        const apiResponse = await chatflowsService.getChatflowByApiKey(apikey.id, apikey.workspaceId, req.query.keyonly)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst getChatflowById = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.getChatflowById - id not provided!`)\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.getChatflowById - workspace ${workspaceId} not found!`\n            )\n        }\n        const apiResponse = await chatflowsService.getChatflowById(req.params.id, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst saveChatflow = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (!req.body) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.saveChatflow - body not provided!`)\n        }\n        const orgId = req.user?.activeOrganizationId\n        if (!orgId) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L116-L152","documentation":"Thrown by getChatflowById when req.user?.activeWorkspaceId is absent (after the id check passed). Returns 404 NOT_FOUND — misleading, since the issue is missing workspace context, not a missing chatflow. The chatflow lookup only runs once activeWorkspaceId is present.","triggerScenarios":"Authenticated GET with a token/session lacking activeWorkspaceId. Same root cause as 746 but on the read path: user is in an org but no workspace is selected/assigned.","commonSituations":"Workspace membership missing; client skipped workspace selection after login; stale token pre-dating workspace assignment; auth middleware that resolves workspace did not run.","solutions":["Verify the user has a workspace membership and the active workspace claim is in the token.","Run workspace selection/switch flow after login.","Ensure auth middleware injecting activeWorkspaceId runs on the route.","Decode JWT to confirm the workspace claim."],"exampleFix":"// before: token without workspace claim\n// after: select workspace, then fetch\nawait api.post('/workspaces/select', { workspaceId })\nawait api.get(`/api/v1/chatflows/${id}`)","handlingStrategy":"validation","validationCode":"function hasWorkspaceClaim(user): boolean {\n  return Boolean(user && (user as any).activeWorkspaceId)\n}\nif (!hasWorkspaceClaim(currentUser)) {\n  // run workspace selection before fetching the chatflow\n}","typeGuard":"function hasWorkspaceContext(u: unknown): u is { activeWorkspaceId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeWorkspaceId === 'string' && (u as any).activeWorkspaceId.length > 0\n}","tryCatchPattern":null,"preventionTips":["Run workspace selection after login so the claim is present.","Ensure workspace_user row exists at provisioning.","Verify the workspace-injecting middleware runs on read routes.","Decode the JWT to confirm the workspace claim."],"tags":["flowise","express","auth","workspace","multitenant","controller"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}