{"record":{"id":"96a3a7ae089b1e41","repo":"n8n-io/n8n","slug":"invalid-response-format-from-template-id-api","errorCode":null,"errorMessage":"Invalid response format from template ${id} API","messagePattern":"Invalid response format from template (.+?) API","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-workflow-builder.ee/src/tools/web/templates.ts","lineNumber":111,"sourceCode":" */\nexport async function fetchTemplateByID(id: number): Promise<TemplateFetchResponse> {\n\tconst url = `${N8N_API_BASE_URL}/workflows/templates/${id}`;\n\n\tconst response = await fetch(url, {\n\t\tmethod: 'GET',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAccept: 'application/json',\n\t\t},\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to fetch template ${id}: ${response.status} ${response.statusText}`);\n\t}\n\n\tconst data: unknown = await response.json();\n\tif (!isTemplateFetchResponse(data)) {\n\t\tthrow new Error(`Invalid response format from template ${id} API`);\n\t}\n\treturn data;\n}\n\n/**\n * Result of fetching workflows from templates\n */\nexport interface FetchWorkflowsResult {\n\tworkflows: WorkflowMetadata[];\n\ttotalFound: number;\n\ttemplateIds: number[];\n}\n\n/**\n * Fetch workflows from templates API and return full workflow data\n * Shared utility used by the get-node-examples and node-details tools\n */\nexport async function fetchWorkflowsFromTemplates(","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-workflow-builder.ee/src/tools/web/templates.ts#L93-L129","documentation":"Thrown by fetchTemplateByID after a 2xx response whose body fails the isTemplateFetchResponse guard. The guard requires id:number, name:string, and workflow:object (non-null). Like [240], this is a schema/shape failure on an otherwise-OK HTTP response.","triggerScenarios":"GET /workflows/templates/{id} returns 200 with a body missing id, name, or workflow; the template endpoint ships a new envelope shape; a proxy replaces the body. The status check at line 105 has passed, so the body itself is the problem.","commonSituations":"api.n8n.io schema migration drops or renames the workflow field; a partial response from a caching layer; a template that exists in the search index but whose full payload is malformed.","solutions":["Log response.text() before parsing to capture the actual body for the failing id.","Re-fetch a known-good template id to isolate id-specific corruption from a global schema change.","Check n8n release notes for templates API contract changes.","If a proxy is in play, exclude api.n8n.io from interception."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"function isTemplateFetchResponse(data: unknown): data is TemplateFetchResponse {\n  if (typeof data !== 'object' || data === null) return false;\n  const o = data as Record<string, unknown>;\n  return typeof o.id === 'number' && typeof o.name === 'string'\n    && typeof o.workflow === 'object' && o.workflow !== null;\n}","typeGuard":"function isTemplateFetchResponse(data: unknown): data is TemplateFetchResponse {\n  if (typeof data !== 'object' || data === null) return false;\n  const o = data as Record<string, unknown>;\n  return typeof o.id === 'number' && typeof o.name === 'string'\n    && typeof o.workflow === 'object' && o.workflow !== null;\n}","tryCatchPattern":"try {\n  const tpl = await fetchTemplateByID(id);\n} catch (e) {\n  if (e instanceof Error && /Invalid response format from template/.test(e.message)) {\n    // body shape changed — log raw and fall back to another template id\n  }\n  throw e;\n}","preventionTips":["Snapshot raw bodies in tests so schema drift is caught before production.","Pair every fetchTemplateByID call with a fallback search-based discovery.","Track templates API schema version in integration tests."],"tags":["api","templates","type-guard","network","ai-workflow-builder"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}