langgenius/dify · error · NotFound
API template not found.
Error message
API template not found.
What it means
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.
Source
Thrown at api/controllers/console/datasets/external.py:268
@console_ns.doc(params={"external_knowledge_api_id": "External knowledge API ID"})
@console_ns.response(
200,
"External API template retrieved successfully",
console_ns.models[ExternalKnowledgeApiResponse.__name__],
)
@console_ns.response(404, "Template not found")
@setup_required
@login_required
@account_initialization_required
@with_current_tenant_id
@with_session
def get(self, session: Session, current_tenant_id: str, external_knowledge_api_id: UUID):
external_knowledge_api_id_str = str(external_knowledge_api_id)
external_knowledge_api = ExternalDatasetService.get_external_knowledge_api(
external_knowledge_api_id=external_knowledge_api_id_str, tenant_id=current_tenant_id, session=session
)
if external_knowledge_api is None:
raise NotFound("API template not found.")
return external_knowledge_api_response(external_knowledge_api, session=session).model_dump(mode="json"), 200
@console_ns.doc("update_external_api_template")
@console_ns.doc(description="Update external knowledge API template")
@console_ns.doc(params={"external_knowledge_api_id": "External knowledge API ID"})
@console_ns.expect(console_ns.models[ExternalKnowledgeApiPayload.__name__])
@console_ns.response(
200,
"External API template updated successfully",
console_ns.models[ExternalKnowledgeApiResponse.__name__],
)
@console_ns.response(404, "Template not found")
@setup_required
@login_required
@account_initialization_required
@with_current_user
@with_current_tenant_idView on GitHub (pinned to ef8544b173)
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.
Example fix
// before
GET .../external-knowledge-api/{deleted_id} -> 404
// after
GET .../external-knowledge-api -> resolve current id
GET .../external-knowledge-api/{current_id} Defensive patterns
Strategy: validation
Validate before calling
async function getExternalApiTemplateSafe(id) {
const r = await fetch(`/console/api/datasets/external-knowledge-api/${id}`);
if (r.status === 404) {
// resolve a current id from the list
const list = await fetch('/console/api/datasets/external-knowledge-api').then(r => r.json());
const found = (list.data || []).find(t => t.id === id || t.name === fallbackName);
if (!found) throw new Error('template does not exist; recreate it');
return fetch(`/console/api/datasets/external-knowledge-api/${found.id}`);
}
return r;
} Type guard
const isValidTemplateId = (id) => typeof id === 'string' && /^[0-9a-fA-F-]{36}$/.test(id); Try / catch
try { return await getTemplate(id); }
catch (e) { if (e.status === 404) { await refreshTemplateList(); throw e; } throw e; } Prevention
- Resolve template ids from the list endpoint, not from cached URLs.
- Refresh the management UI before opening template detail.
When it happens
Trigger: 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.
Common situations: Stale template id from a bookmark; template deleted by another admin; cross-tenant id reused from a shared config.
Related errors
- export response missing data field
- UploadFile not found.
- The job does not exist.
- Dataset not found.
- Document not found.
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/9ae893d078a72525.
Report an issue: GitHub.