{"record":{"id":"1a1f31c65122efce","repo":"FlowiseAI/Flowise","slug":"error-assistantscontroller-createassistant-work","errorCode":null,"errorMessage":"Error: assistantsController.createAssistant - workspace ${workspaceId} not found!","messagePattern":"Error: assistantsController\\.createAssistant - workspace (.+?) not found!","errorType":"validation","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/assistants/index.ts","lineNumber":27,"sourceCode":"const 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)\n\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/assistants/index.ts#L9-L45","documentation":"Thrown by createAssistant with HTTP 404 after body and organization checks pass, when workspaceId = req.user?.activeWorkspaceId is falsy. The interpolated message reads 'workspace undefined not found'. Even with an org selected, an active workspace must also be present because assistants are scoped per workspace.","triggerScenarios":"POST /api/v1/assistants with a valid body and a valid activeOrganizationId, but no activeWorkspaceId in the session — the user selected an org but not a workspace, or has no workspace membership.","commonSituations":"Workspace creation/selection step skipped after org selection; workspace membership deleted; session created before workspace onboarding completed.","solutions":["Select/switch into a workspace so the session carries activeWorkspaceId, then retry the POST.","Verify the user has a workspace membership; create one if missing.","Confirm auth middleware sets activeWorkspaceId on req.user."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const hasActiveWorkspace = (u: unknown): u is { activeWorkspaceId: string } =>\n  !!u && typeof u === 'object' &&\n  typeof (u as any).activeWorkspaceId === 'string' &&\n  (u as any).activeWorkspaceId.length > 0","tryCatchPattern":"try {\n  await createAssistant(payload)\n} catch (err) {\n  if (err?.statusCode === 404 && /workspace .* not found/i.test(err.message)) {\n    await selectWorkspace()\n    return createAssistant(payload)\n  }\n  throw err\n}","preventionTips":["Require an active workspace (not just an org) before creating an assistant.","Handle workspace 404s by re-running workspace selection and retrying once.","Validate workspace membership exists for the user."],"tags":["authentication","session","workspace","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"}