{"record":{"id":"cf9cf783eb2a7b7f","repo":"n8n-io/n8n","slug":"could-not-find-the-folder-folderid","errorCode":null,"errorMessage":"Could not find the folder: ${folderId}","messagePattern":"Could not find the folder: (.+?)","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"warning","filePath":"packages/cli/src/controllers/folder.controller.ts","lineNumber":73,"sourceCode":"\t\t}\n\t}\n\n\t@Post('/')\n\t@ProjectScope('folder:create')\n\t@Licensed('feat:folders')\n\tasync createFolder(\n\t\treq: AuthenticatedRequest<{ projectId: string }>,\n\t\t_res: Response,\n\t\t@Body payload: CreateFolderDto,\n\t) {\n\t\tconst { projectId } = req.params;\n\n\t\ttry {\n\t\t\tconst folder = await this.folderService.createFolder(payload, projectId);\n\t\t\treturn folder;\n\t\t} catch (e) {\n\t\t\tif (e instanceof FolderNotFoundError) {\n\t\t\t\tthrow new NotFoundError(e.message);\n\t\t\t}\n\t\t\tthrow new InternalServerError(undefined, e);\n\t\t}\n\t}\n\n\t@Get('/:folderId/tree')\n\t@ProjectScope('folder:read')\n\t@Licensed('feat:folders')\n\tasync getFolderTree(\n\t\treq: AuthenticatedRequest<{ projectId: string; folderId: string }>,\n\t\t_res: Response,\n\t) {\n\t\tconst { projectId, folderId } = req.params;\n\n\t\ttry {\n\t\t\tconst tree = await this.folderService.getFolderTree(folderId, projectId);\n\t\t\treturn tree;\n\t\t} catch (e) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/controllers/folder.controller.ts#L55-L91","documentation":"NotFoundError (HTTP 404) whose message is the `FolderNotFoundError.message` (template 'Could not find the folder: <folderId>'), re-thrown at folder.controller.ts:73 inside `createFolder` when `folderService.createFolder(payload, projectId)` rejects with `FolderNotFoundError` — typically because the requested parent folder in the payload does not exist in the project.","triggerScenarios":"POST `/projects/<projectId>/folders` with a `parentFolderId` (inside the `CreateFolderDto`) that does not exist in that project. The service lookup of the parent fails and surfaces as `FolderNotFoundError`.","commonSituations":"UI bug sending a stale parent ID; parent folder deleted between dialog open and submit; cross-project parent reference; manually crafted payloads with wrong IDs.","solutions":["Confirm the parent folder exists in the same project via `GET /projects/<projectId>/folders`.","Omit `parentFolderId` (or set to null) to create at the project root.","Refresh the folder tree before submitting and re-send with the current parent ID.","Guard against deleted parents in the client before submit."],"exampleFix":"// before\nPOST /projects/p1/folders  { \"parentFolderId\": \"stale-xyz\", \"name\": \"Sub\" }\n// 404 Could not find the folder: stale-xyz\n\n// after\nPOST /projects/p1/folders  { \"name\": \"Root\" }","handlingStrategy":"validation","validationCode":"async function parentExists(svc: FolderService, projectId: string, parentId?: string) {\n  if (!parentId) return true; // root\n  try { await svc.getFolderTree(parentId, projectId); return true; } catch { return false; }\n}\n// gate createFolder on parentExists(...)","typeGuard":"const isCreateFolderDto = (p: unknown): p is { name: string; parentFolderId?: string } =>\n  typeof p === 'object' && p !== null && typeof (p as any).name === 'string';","tryCatchPattern":"try { await createFolder(payload, projectId); }\ncatch (e) { if (e instanceof NotFoundError && /Could not find the folder/.test(e.message)) { /* clear stale parent id */ } }","preventionTips":["Refresh the folder tree before showing the create dialog so parent IDs are current.","Invalidate cached parent IDs when a folder is deleted.","Default to root creation when the parent ID is uncertain."],"tags":["folders","rest","not-found","projects"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}