{"record":{"id":"3141ea524b25dfa5","repo":"FlowiseAI/Flowise","slug":"error-apikeycontroller-createapikey-keyname-not","errorCode":null,"errorMessage":"Error: apikeyController.createApiKey - keyName not provided!","messagePattern":"Error: apikeyController\\.createApiKey - keyName not provided!","errorType":"validation","errorClass":"InternalFlowiseError","httpStatus":412,"severity":"warning","filePath":"packages/server/src/controllers/apikey/index.ts","lineNumber":27,"sourceCode":"const getAllApiKeys = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        const user = req.user as LoggedInUser\n\n        if (req.query?.type === 'organization' && user.isOrganizationAdmin)\n            return res.status(StatusCodes.OK).json(await apikeyService.getAllApiKeysByOrganization(user.activeOrganizationId))\n\n        const { page, limit } = getPageAndLimitParams(req)\n        const apiResponse = await apikeyService.getAllApiKeys(user, page, limit)\n        return res.status(StatusCodes.OK).json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst createApiKey = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.body === 'undefined' || !req.body.keyName) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)\n        }\n        if (\n            !req.body.permissions ||\n            !Array.isArray(req.body.permissions) ||\n            req.body.permissions.length === 0 ||\n            !req.body.permissions.every((p: any) => typeof p === 'string')\n        ) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: apikeyController.createApiKey - permissions must be an array of strings!`\n            )\n        }\n        const user = req.user as LoggedInUser\n        const apiResponse = await apikeyService.createApiKey(user, req.body.keyName, req.body.permissions)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/apikey/index.ts#L9-L45","documentation":"createApiKey handler requires req.body.keyName to be truthy. If req.body is undefined or keyName is missing/empty, it throws InternalFlowiseError with HTTP 412 PRECONDITION_FAILED. This is a client-input guard run before permissions validation and before the service creates the key.","triggerScenarios":"POST to the create-api-key endpoint with a body lacking keyName (omitted, empty string, or null), or with no body at all.","commonSituations":"Frontend form submitted with the key-name field blank. Client sends permissions but forgets the name. Body-parsing middleware not mounted so req.body is undefined.","solutions":["Send a non-empty 'keyName' string in the JSON request body.","Validate the form client-side and disable submit until keyName is provided.","Ensure express.json() middleware is active so req.body is parsed.","Return the field name in the client error display so the user knows what to fix."],"exampleFix":"// before\nif (typeof req.body === 'undefined' || !req.body.keyName) {\n    throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.createApiKey - keyName not provided!`)\n}\n\n// after\nif (!req.body?.keyName || typeof req.body.keyName !== 'string') {\n    throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'keyName is required and must be a non-empty string')\n}","handlingStrategy":"validation","validationCode":"function requireKeyName(body: any): asserts body is { keyName: string } {\n    if (!body || typeof body.keyName !== 'string' || !body.keyName) {\n        throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'keyName is required')\n    }\n}\nrequireKeyName(req.body)","typeGuard":"function hasKeyName(body: unknown): body is { keyName: string } {\n    return typeof (body as any)?.keyName === 'string' && (body as any).keyName.length > 0\n}","tryCatchPattern":"// The handler already routes through next(error); a global error handler should map\n// InternalFlowiseError.statusCode to the HTTP status. No additional catch needed if the\n// error middleware respects statusCode.","preventionTips":["Send a non-empty 'keyName' string in the JSON body.","Validate the form client-side and disable submit until keyName is provided.","Ensure express.json() is mounted so req.body is defined.","Display the returned message so the user knows which field to fix."],"tags":["validation","controller","apikey","input-validation","express"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}