{"record":{"id":"dc85cc5d06c66f1d","repo":"FlowiseAI/Flowise","slug":"error-assistantscontroller-createassistant-orga","errorCode":null,"errorMessage":"Error: assistantsController.createAssistant - organization ${orgId} not found!","messagePattern":"Error: assistantsController\\.createAssistant - organization (.+?) not found!","errorType":"validation","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/assistants/index.ts","lineNumber":20,"sourceCode":"import { StatusCodes } from 'http-status-codes'\nimport { InternalFlowiseError } from '../../errors/internalFlowiseError'\nimport { AssistantType } from '../../Interface'\nimport assistantsService from '../../services/assistants'\nimport { getRunningExpressApp } from '../../utils/getRunningExpressApp'\nimport { checkUsageLimit } from '../../utils/quotaUsage'\n\nconst createAssistant = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (!req.body) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: assistantsController.createAssistant - body not provided!`\n            )\n        }\n        const body = req.body\n        const orgId = req.user?.activeOrganizationId\n        if (!orgId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: assistantsController.createAssistant - 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: assistantsController.createAssistant - workspace ${workspaceId} not found!`\n            )\n        }\n        const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''\n\n        const existingAssistantCount = await assistantsService.getAssistantsCountByOrganization(body.type, orgId)\n        const newAssistantCount = 1\n        await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingAssistantCount + newAssistantCount)\n\n        const apiResponse = await assistantsService.createAssistant(body, orgId, workspaceId)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/assistants/index.ts#L2-L38","documentation":"Thrown by createAssistant with HTTP 404 (NOT_FOUND) after the body guard passes, when orgId = req.user?.activeOrganizationId is falsy. The interpolated value in the message will be 'undefined' or 'null'. The organization id is attached by the auth/session middleware; its absence means the caller is authenticated but has no active organization context, so the assistant cannot be scoped/created.","triggerScenarios":"POST /api/v1/assistants with a valid JSON body from a session whose JWT has no activeOrganizationId — e.g. a user not belonging to any organization, or an org claim that was never set.","commonSituations":"User invited but not yet assigned to an organization; SSO/JIT provisioning that created the user without an org; JWT minted without the org claim; running in a non-enterprise/single-user mode where activeOrganizationId is never populated but this enterprise-guarded route is still reached.","solutions":["Ensure the user belongs to an organization and the session/JWT carries activeOrganizationId before creating an assistant.","Have the client select/switch into an organization, then retry.","Verify the auth middleware populates activeOrganizationId on req.user for this deployment."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const hasActiveOrg = (u: unknown): u is { activeOrganizationId: string } =>\n  !!u && typeof u === 'object' &&\n  typeof (u as any).activeOrganizationId === 'string' &&\n  (u as any).activeOrganizationId.length > 0","tryCatchPattern":"try {\n  await createAssistant(payload)\n} catch (err) {\n  if (err?.statusCode === 404 && /organization .* not found/i.test(err.message)) {\n    await selectOrganization() // establish activeOrganizationId\n    return createAssistant(payload)\n  }\n  throw err\n}","preventionTips":["Require an active organization in the session before enabling assistant creation.","On 404 'organization ... not found', prompt org selection then retry once.","Ensure provisioning assigns every user to an org."],"tags":["authentication","session","organization","not-found","express","flowise","assistants"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}