{"record":{"id":"79ed8894378e2ea9","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-savechatflow-workspac","errorCode":null,"errorMessage":"Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!","messagePattern":"Error: chatflowsController\\.saveChatflow - workspace (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":160,"sourceCode":"        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) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.saveChatflow - organization ${orgId} not found!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`\n            )\n        }\n        const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''\n        const body = req.body\n\n        const existingChatflowCount = await chatflowsService.getAllChatflowsCountByOrganization(body.type, orgId)\n        const newChatflowCount = 1\n        await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingChatflowCount + newChatflowCount)\n\n        const newChatFlow = new ChatFlow()\n        Object.assign(newChatFlow, stripProtectedFields(body))\n\n        newChatFlow.workspaceId = workspaceId\n        const apiResponse = await chatflowsService.saveChatflow(\n            newChatFlow,\n            orgId,","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L142-L178","documentation":"Thrown by saveChatflow when req.user?.activeWorkspaceId is absent (after org check). Returns 404 NOT_FOUND — misleading; the user context is incomplete, no record is being searched. The chatflow is only created once all three (body, orgId, workspaceId) are present.","triggerScenarios":"Authenticated POST with body and org claim but no activeWorkspaceId. User is in an org but has not selected/been assigned a workspace.","commonSituations":"Workspace membership missing; client skipped workspace selection; workspace-resolving middleware did not run; stale token.","solutions":["Confirm the user has a workspace membership row.","Run the workspace selection flow after login.","Ensure auth middleware injecting activeWorkspaceId runs on the route.","Decode the token and verify the workspace claim."],"exampleFix":"// before: no workspace claim\n// after: select workspace then create\nawait api.post('/workspaces/select', { workspaceId })\nawait api.post('/api/v1/chatflows', payload)","handlingStrategy":"validation","validationCode":"function hasWorkspaceClaim(user): boolean {\n  return Boolean(user && (user as any).activeWorkspaceId)\n}\nif (!hasWorkspaceClaim(currentUser)) {\n  // run workspace selection before saving\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.","Ensure workspace_user row exists at provisioning.","Verify workspace-injecting middleware runs on save routes.","Decode the JWT to confirm the workspace claim."],"tags":["flowise","express","auth","workspace","multitenant","controller","create"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}