导入数据源条目
将在线文档页面或在线云盘文件导入连接器数据源,并返回运行。用其 id 轮询 获取数据源运行,直到 state 为 completed、failed 或 canceled。
这些条目会替换数据源的文档:导入完成后,数据源中不在 items 里的条目,其文档会被删除。需发送希望数据源保留的所有条目。
数据源首次导入完成后,之后的导入只能包含那次导入中的条目。新条目会使运行以 SOURCE_OPERATION_FAILED 失败,重试也无法解决:新条目需在 Dify 中添加到数据源。
数据源必须是 connector 类型,且 kind 必须与其 metadata.providerKind 一致。一个数据源同一时间只运行一个同步、预览或导入,因此需先等当前运行结束。
先浏览后导入的流程,详见 导入在线文档和云盘文件。
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/workflow-imports \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"items": [
{
"lastEditedTime": "2026-09-01T12:00:00.000Z",
"name": "Onboarding",
"pageId": "3f9a1c2b-7d4e-4f5a-8b6c-9d0e1f2a3b4c",
"providerItemId": "[\"ws_01HZYQ8K3M\",\"3f9a1c2b-7d4e-4f5a-8b6c-9d0e1f2a3b4c\"]",
"type": "page",
"workspaceId": "ws_01HZYQ8K3M"
},
{
"lastEditedTime": "2026-08-20T09:30:00.000Z",
"name": "Runbooks",
"pageId": "5c1b2d3e-8f4a-4b6c-9d7e-0f1a2b3c4d5e",
"providerItemId": "[\"ws_01HZYQ8K3M\",\"5c1b2d3e-8f4a-4b6c-9d7e-0f1a2b3c4d5e\"]",
"type": "database",
"workspaceId": "ws_01HZYQ8K3M"
}
],
"kind": "online-document-import"
}
'{
"canceled_at": null,
"checkpoint": "queued",
"completed_at": null,
"created_at": "2026-10-20T10:00:00Z",
"cursor": null,
"execution_attempts": 0,
"failure": null,
"id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
"kind": "online-document-import",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_error_code": null,
"max_execution_attempts": 5,
"progress_completed": 0,
"progress_failed": 0,
"progress_skipped": 0,
"progress_total": 2,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"state": "queued",
"updated_at": "2026-10-20T10:00:00Z"
}Authorizations
每个请求都通过 API 密钥认证:Authorization: Bearer {API_KEY}。应用接口使用应用 API 密钥,知识库接口使用知识库 API 密钥(快速开始)。
API 密钥应保存在服务端,切勿嵌入客户端代码。缺失或无效的密钥会返回 HTTP 401(unauthorized)。
Headers
Body
规范化后的请求不得超过 4,194,304 个 UTF-8 字节。参见 请求大小限制。
- 在线文档页面
- 在线云盘文件
Response
运行,其中 kind 与请求一致、state: queued,progress_total 为条目数量。
运行已到达的最后一步:queued、provider-read、preview-staged、selection-frozen、materialized、cleanup-staging 或 source-committed。无论运行停在哪个检查点,重试数据源运行 都会从头开始运行。
工作进程领取该运行的次数,包括 重试数据源运行 之后的领取,重试不会重置该值。
execution_attempts 的上限。达到上限后,重试数据源运行 返回 409。
运行预计处理的项数:导入请求的页面或条目数、抓取预览目前已暂存的页面数,或同步列出数据源条目后的条目数。确定之前为 null。
导入网站页面 的运行抓取 URL 期间,progress_completed 和 progress_total 都统计目前已抓取的页面数。所有 URL 抓取完成后,进度从 0 重新开始计,总数变为 URL 的数量。
Was this page helpful?
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/workflow-imports \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"items": [
{
"lastEditedTime": "2026-09-01T12:00:00.000Z",
"name": "Onboarding",
"pageId": "3f9a1c2b-7d4e-4f5a-8b6c-9d0e1f2a3b4c",
"providerItemId": "[\"ws_01HZYQ8K3M\",\"3f9a1c2b-7d4e-4f5a-8b6c-9d0e1f2a3b4c\"]",
"type": "page",
"workspaceId": "ws_01HZYQ8K3M"
},
{
"lastEditedTime": "2026-08-20T09:30:00.000Z",
"name": "Runbooks",
"pageId": "5c1b2d3e-8f4a-4b6c-9d7e-0f1a2b3c4d5e",
"providerItemId": "[\"ws_01HZYQ8K3M\",\"5c1b2d3e-8f4a-4b6c-9d7e-0f1a2b3c4d5e\"]",
"type": "database",
"workspaceId": "ws_01HZYQ8K3M"
}
],
"kind": "online-document-import"
}
'{
"canceled_at": null,
"checkpoint": "queued",
"completed_at": null,
"created_at": "2026-10-20T10:00:00Z",
"cursor": null,
"execution_attempts": 0,
"failure": null,
"id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
"kind": "online-document-import",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_error_code": null,
"max_execution_attempts": 5,
"progress_completed": 0,
"progress_failed": 0,
"progress_skipped": 0,
"progress_total": 2,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"state": "queued",
"updated_at": "2026-10-20T10:00:00Z"
}