{"record":{"id":"db2752dd1154a733","repo":"FlowiseAI/Flowise","slug":"error-credentialscontroller-getcredentialbyid-i","errorCode":null,"errorMessage":"Error: credentialsController.getCredentialById - id not provided!","messagePattern":"Error: credentialsController\\.getCredentialById - id not provided!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":412,"severity":"warning","filePath":"packages/server/src/controllers/credentials/index.ts","lineNumber":64,"sourceCode":"    try {\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: credentialsController.getAllCredentials - workspace ${workspaceId} not found!`\n            )\n        }\n        const apiResponse = await credentialsService.getAllCredentials(req.query.credentialName, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst getCredentialById = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                `Error: credentialsController.getCredentialById - id not provided!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: credentialsController.getCredentialById - workspace ${workspaceId} not found!`\n            )\n        }\n        const apiResponse = await credentialsService.getCredentialById(req.params.id, workspaceId)\n        return res.json(apiResponse)\n    } catch (error) {\n        next(error)\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/credentials/index.ts#L46-L82","documentation":"Thrown by getCredentialById when req.params.id is undefined or empty. The guard uses typeof req.params === 'undefined' || !req.params.id, so it fires for a missing :id route param, an empty string, or a literal 'undefined'. This is a client-side URL construction bug, not an auth or DB issue. Returns HTTP 412 PRECONDITION_FAILED.","triggerScenarios":"GET /api/v1/credentials/ (trailing slash, no id). GET /api/v1/credentials/undefined or /api/v1/credentials/null from a frontend that stringified an undefined variable into the path. Route mis-mounted so :id never parses.","commonSituations":"Frontend template like `/credentials/${selected?.id}` where selected is null on first render. Copy-paste of an API path that drops the id segment. Client building URLs from a form field the user left blank.","solutions":["Inspect the outgoing request URL in the browser network tab and confirm the id segment is a real UUID.","On the client, guard the fetch: only call getCredentialById when typeof id === 'string' && id.length > 0.","If using react-query/sWR, enable the query only when id is truthy (enabled: !!id).","Verify the route is registered with the :id param (app.get('/credentials/:id', ...)) and not accidentally mounted as '/credentials/')."],"exampleFix":"// before\nconst res = await fetch(`/api/v1/credentials/${id}`) // id may be undefined\n\n// after\nif (!id) throw new Error('credential id required')\nconst res = await fetch(`/api/v1/credentials/${encodeURIComponent(id)}`)","handlingStrategy":"type-guard","validationCode":"function requireCredentialId(id: unknown): string {\n  if (typeof id !== 'string' || id.trim().length === 0) {\n    throw new Error('credential id is required')\n  }\n  return id\n}\n\nconst id = requireCredentialId(params.id)\nawait api.getCredentialById(id)","typeGuard":"function isNonEmptyString(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":"try {\n  await api.getCredentialById(id)\n} catch (e) {\n  if (e.status === 412 && /id not provided/.test(e.message)) {\n    // programming error — do not retry; fix the caller\n    console.error('caller passed an empty credential id')\n  }\n  throw e\n}","preventionTips":["Build URL templates like `/credentials/${encodeURIComponent(id)}` only after a non-empty id check.","For react-query / SWR, set `enabled: !!id` so the request waits for a real id.","Never stringify undefined/null into a URL path — guard first."],"tags":["validation","rest-params","client-bug","credentials","flowise"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}