langgenius/dify · error · NotFound
Credential not found.
Error message
Credential not found.
What it means
Flask NotFound (HTTP 404) raised at data_source.py:249 in DataSourceNotionListApi.get (GET /data-source/notion/pre-import/pages) when DatasourceProviderService.get_datasource_credentials returns a falsy value for the given credential_id, provider='notion_datasource', plugin_id='langgenius/notion_datasource'. The Notion OAuth credential for this tenant/credential_id does not exist (or was revoked) in the credentials store.
Source
Thrown at api/controllers/console/datasets/data_source.py:249
@with_current_tenant_id
@with_session(write=False)
@model_validate(DataSourceNotionListQuery)
def get(
self,
req_data: DataSourceNotionListQuery,
session: Session,
current_tenant_id: str,
current_user: Account,
) -> tuple[dict[str, Any], int]:
datasource_provider_service = DatasourceProviderService()
credential = datasource_provider_service.get_datasource_credentials(
tenant_id=current_tenant_id,
credential_id=req_data.credential_id,
provider="notion_datasource",
plugin_id="langgenius/notion_datasource",
)
if not credential:
raise NotFound("Credential not found.")
exist_page_ids = []
# import notion in the exist dataset
if req_data.dataset_id:
dataset = DatasetService.get_dataset(req_data.dataset_id, session)
if not dataset:
raise NotFound("Dataset not found.")
if dataset.data_source_type != "notion_import":
raise ValueError("Dataset is not notion type.")
documents = session.scalars(
select(Document).where(
Document.dataset_id == req_data.dataset_id,
Document.tenant_id == current_tenant_id,
Document.data_source_type == "notion_import",
Document.enabled.is_(True),
)
).all()
if documents:View on GitHub (pinned to ef8544b173)
Solutions
- Re-authorize the Notion datasource to obtain a fresh credential_id, then use that id in the query.
- List existing credentials for the tenant to find the current notion_datasource credential_id.
- Confirm the plugin 'langgenius/notion_datasource' is installed and enabled; a missing plugin yields no credential.
- Ensure the request is scoped to the tenant that owns the credential.
Defensive patterns
Strategy: validation
Validate before calling
// Verify the credential exists before listing Notion pages.
const creds = await listDatasourceCredentials(currentTenantId);
if (!creds.some(c => c.id === credentialId && c.provider === 'notion_datasource')) {
throw new Error('Re-authorize Notion to get a fresh credential_id');
} Type guard
function isNotionCredential(c: {provider: string; id: string}, id: string): boolean {
return c.provider === 'notion_datasource' && c.id === id;
} Try / catch
try {
await listNotionPages(credentialId);
} catch (e) {
if (e.status === 404 && /Credential not found/i.test(e.message)) { reAuthNotion(); }
else throw e;
} Prevention
- Re-authorize Notion when the wizard is reopened after a long gap.
- Pass the credential_id returned by the most recent authorization.
- Confirm the notion_datasource plugin is installed.
When it happens
Trigger: GET /console/api/data-source/notion/pre-import/pages?credential_id=<id> where the credential_id is unknown, belongs to another tenant, or the Notion datasource credential was deleted/expired before this pre-import listing call.
Common situations: User opened the Notion import wizard with a stale credential_id (e.g. after re-authenticating Notion which created a new credential); credential store cleanup removed the old entry; or the plugin credential was never successfully saved.
Related errors
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/c7edc4165c8bdbec.
Report an issue: GitHub.