{"record":{"id":"9dc2039ab0f9e401","repo":"FlowiseAI/Flowise","slug":"error-chatflowscontroller-savechatflow-organiza","errorCode":null,"errorMessage":"Error: chatflowsController.saveChatflow - organization ${orgId} not found!","messagePattern":"Error: chatflowsController\\.saveChatflow - organization (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chatflows/index.ts","lineNumber":153,"sourceCode":"                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) {\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","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chatflows/index.ts#L135-L171","documentation":"Thrown by saveChatflow when req.user?.activeOrganizationId is absent (after the body check). Returns 404 NOT_FOUND — misleading code; the missing value is an auth-context field. Indicates the session/token has no org claim.","triggerScenarios":"Authenticated POST with body present but token lacking activeOrganizationId. Common for fresh accounts without org membership or tokens minted before the multitenant rollout.","commonSituations":"User has no organization membership; org-resolving auth middleware did not run; legacy token; test stub missing the field.","solutions":["Decode JWT and confirm activeOrganizationId is present.","Ensure the user has at least one org membership; assign one if missing.","Verify auth middleware that injects the org claim runs on the route.","Re-login / refresh token after org assignment."],"exampleFix":"// before: token without org claim\n// after: ensure org membership, re-login\nawait api.post('/auth/login', creds)\nawait api.post('/api/v1/chatflows', payload)","handlingStrategy":"validation","validationCode":"function hasOrgClaim(user): boolean {\n  return Boolean(user && (user as any).activeOrganizationId)\n}\nif (!hasOrgClaim(currentUser)) {\n  // ensure org membership / re-login instead of saving\n}","typeGuard":"function hasOrgContext(u: unknown): u is { activeOrganizationId: string } {\n  return typeof u === 'object' && u !== null\n    && typeof (u as any).activeOrganizationId === 'string' && (u as any).activeOrganizationId.length > 0\n}","tryCatchPattern":null,"preventionTips":["Provision every user with at least one org membership.","Verify org-injecting auth middleware runs on save routes.","Decode the JWT to confirm the org claim.","Re-login after org assignment."],"tags":["flowise","express","auth","organization","multitenant","controller","create"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}