{"record":{"id":"9ae893d078a72525","repo":"langgenius/dify","slug":"api-template-not-found","errorCode":null,"errorMessage":"API template not found.","messagePattern":"API template not found\\.","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/datasets/external.py","lineNumber":268,"sourceCode":"    @console_ns.doc(params={\"external_knowledge_api_id\": \"External knowledge API ID\"})\n    @console_ns.response(\n        200,\n        \"External API template retrieved successfully\",\n        console_ns.models[ExternalKnowledgeApiResponse.__name__],\n    )\n    @console_ns.response(404, \"Template not found\")\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @with_current_tenant_id\n    @with_session\n    def get(self, session: Session, current_tenant_id: str, external_knowledge_api_id: UUID):\n        external_knowledge_api_id_str = str(external_knowledge_api_id)\n        external_knowledge_api = ExternalDatasetService.get_external_knowledge_api(\n            external_knowledge_api_id=external_knowledge_api_id_str, tenant_id=current_tenant_id, session=session\n        )\n        if external_knowledge_api is None:\n            raise NotFound(\"API template not found.\")\n\n        return external_knowledge_api_response(external_knowledge_api, session=session).model_dump(mode=\"json\"), 200\n\n    @console_ns.doc(\"update_external_api_template\")\n    @console_ns.doc(description=\"Update external knowledge API template\")\n    @console_ns.doc(params={\"external_knowledge_api_id\": \"External knowledge API ID\"})\n    @console_ns.expect(console_ns.models[ExternalKnowledgeApiPayload.__name__])\n    @console_ns.response(\n        200,\n        \"External API template updated successfully\",\n        console_ns.models[ExternalKnowledgeApiResponse.__name__],\n    )\n    @console_ns.response(404, \"Template not found\")\n    @setup_required\n    @login_required\n    @account_initialization_required\n    @with_current_user\n    @with_current_tenant_id","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/datasets/external.py#L250-L286","documentation":"Raised by the GET external-knowledge-API-template handler when ExternalDatasetService.get_external_knowledge_api returns None for the given external_knowledge_api_id scoped to the current tenant. The template does not exist, was deleted, or is not accessible to this tenant.","triggerScenarios":"GET /console/api/datasets/external-knowledge-api/{external_knowledge_api_id} with an id that does not exist in the current tenant or was deleted.","commonSituations":"Stale template id from a bookmark; template deleted by another admin; cross-tenant id reused from a shared config.","solutions":["List external knowledge APIs first to resolve a current id.","If the template was deleted, recreate it and use the new id.","Refresh the management UI before opening template detail."],"exampleFix":"// before\nGET .../external-knowledge-api/{deleted_id}  -> 404\n// after\nGET .../external-knowledge-api  -> resolve current id\nGET .../external-knowledge-api/{current_id}","handlingStrategy":"validation","validationCode":"async function getExternalApiTemplateSafe(id) {\n  const r = await fetch(`/console/api/datasets/external-knowledge-api/${id}`);\n  if (r.status === 404) {\n    // resolve a current id from the list\n    const list = await fetch('/console/api/datasets/external-knowledge-api').then(r => r.json());\n    const found = (list.data || []).find(t => t.id === id || t.name === fallbackName);\n    if (!found) throw new Error('template does not exist; recreate it');\n    return fetch(`/console/api/datasets/external-knowledge-api/${found.id}`);\n  }\n  return r;\n}","typeGuard":"const isValidTemplateId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id);","tryCatchPattern":"try { return await getTemplate(id); }\ncatch (e) { if (e.status === 404) { await refreshTemplateList(); throw e; } throw e; }","preventionTips":["Resolve template ids from the list endpoint, not from cached URLs.","Refresh the management UI before opening template detail."],"tags":["datasets","external-knowledge","not-found","rest-api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}