{"record":{"id":"ef4d7a9ed30e7672","repo":"FlowiseAI/Flowise","slug":"error-apikeycontroller-updateapikey-keyname-not","errorCode":null,"errorMessage":"Error: apikeyController.updateApiKey - keyName not provided!","messagePattern":"Error: apikeyController\\.updateApiKey - keyName not provided!","errorType":"validation","errorClass":"InternalFlowiseError","httpStatus":412,"severity":"warning","filePath":"packages/server/src/controllers/apikey/index.ts","lineNumber":55,"sourceCode":"                `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    }\n}\n\n// Update api key\nconst updateApiKey = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - id not provided!`)\n        }\n        if (typeof req.body === 'undefined' || !req.body.keyName) {\n            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - 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.updateApiKey - permissions must be an array of strings!`\n            )\n        }\n        const user = req.user as LoggedInUser\n        const apiResponse = await apikeyService.updateApiKey(user, req.params.id, req.body.keyName, req.body.permissions)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/apikey/index.ts#L37-L73","documentation":"updateApiKey handler checks, after the id guard, that req.body.keyName is truthy; if req.body is undefined or keyName is missing/empty, it throws InternalFlowiseError 412. The update service requires a new keyName to apply, so an absent name cannot proceed.","triggerScenarios":"PUT/PATCH to update-api-key with a valid id in the path but a body missing keyName (omitted, empty, or null), or no body at all.","commonSituations":"Client sends only permissions in the update body, forgetting keyName. Form submitted with a blank name field. Body-parsing middleware not mounted so req.body is undefined.","solutions":["Include a non-empty 'keyName' string in the JSON body of the update request.","Pre-fill the form with the current name so an empty submit can't happen.","Ensure express.json() middleware is active so req.body is parsed.","If partial updates are intended, make keyName optional in the service and skip the check when absent."],"exampleFix":"// before\nif (typeof req.body === 'undefined' || !req.body.keyName) {\n    throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: apikeyController.updateApiKey - 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":"// Relies on the global error handler mapping InternalFlowiseError.statusCode (412) to HTTP.","preventionTips":["Include a non-empty 'keyName' string in the update body.","Pre-fill the form with the current name so submits aren't blank.","Ensure express.json() is mounted so req.body is defined.","If partial updates are intended, make keyName optional and skip the check when absent."],"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"}