ウェブサイトのページをインポート
既知の URL をウェブサイトソースにインポートし、実行を返します。state が completed、failed、canceled のいずれかになるまで、その id で ソースの実行を取得 をポーリングしてください。
各 URL は個別にクロールされ、すべての URL のクロールが終わるとインポートが始まります。ページを返さない URL があると、ページがインポートされる前に実行が失敗し、ソースのドキュメントは変更されません。
実行が完了すると、sourceUrls がソースのページリストになります。インポートのたびにリスト全体が設定されるため、ソースに残したい URL はすべて送信してください。
ソースは web ソースである必要があります。1 つのソースで同時に実行できる同期、プレビュー、インポートは 1 つだけです。別の実行を開始する前に、アクティブな実行が終わるのを待ってください。インポートしないクロールプレビューはキャンセルしてください。
ウェブサイトのページをインポートする 2 つの方法については、ウェブサイトのページのインポート を参照してください。
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"replaceExistingSelection": true,
"sourceUrls": [
"https://docs.example.com/guides/billing",
"https://docs.example.com/pricing"
]
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import"
payload = {
"replaceExistingSelection": True,
"sourceUrls": ["https://docs.example.com/guides/billing", "https://docs.example.com/pricing"]
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
replaceExistingSelection: true,
sourceUrls: ['https://docs.example.com/guides/billing', 'https://docs.example.com/pricing']
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'replaceExistingSelection' => true,
'sourceUrls' => [
'https://docs.example.com/guides/billing',
'https://docs.example.com/pricing'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import"
payload := strings.NewReader("{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"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": "crawl-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
すべてのリクエストは、Authorization: Bearer {API_KEY} ヘッダーに指定した API キーで認証します。アプリのエンドポイントにはアプリの API キーを、ナレッジのエンドポイントにはナレッジベースの API キーを使用します(Dify API クイックスタート)。
キーはサーバーサイドで保管し、クライアントコードには決して埋め込まないでください。キーがない、または無効な場合は HTTP 401(unauthorized)が返ります。
Headers
Body
正規化後のリクエストは、UTF-8 で 1,048,576 バイト以内に収める必要があります。リクエストサイズの制限 を参照してください。
Response
kind: crawl-import、state: queued で、progress_total に URL の数が設定された実行です。
実行が到達した最後のステップで、queued、provider-read、preview-staged、selection-frozen、materialized、cleanup-staging、source-committed のいずれかです。ソースの実行を再試行 は、チェックポイントにかかわらず実行を最初からやり直します。
ワーカーが実行を取得した回数です。ソースの実行を再試行 の後の取得も含み、再試行してもリセットされません。
実行 ID です。ソースの実行を取得、ソースの実行をキャンセル、ソースの実行を再試行 に渡します。
実行の処理内容です:
sync:ソースを同期、ソースを更新、スケジュール、または Dify によって開始されます。crawl-preview:ウェブサイトのクロールをプレビュー によって開始されます。選択したページをインポート がこの実行からインポートしている間も、種類は変わりません。crawl-import:ウェブサイトのページをインポート によって開始されます。online-document-import、online-drive-import:ソースのアイテムをインポート によって開始されます。
Dify でソースを追加または編集した場合も、Dify がプレビューとインポートを開始します。
execution_attempts の上限です。上限に達すると、ソースの実行を再試行 は 409 を返します。
実行が処理する予定のアイテム数です。インポートではリクエストされたページまたはアイテム、クロールプレビューではこれまでに一時保存されたページ、同期では一覧の取得後のソースのアイテムを数えます。判明するまでは null です。
ウェブサイトのページをインポート の実行が URL をクロールしている間は、progress_completed と progress_total のどちらも、それまでにクロールしたページ数を数えます。すべての URL のクロールが終わると、URL の数を総数として 0 から数え直します。
実行の進行状況です。
進行中の状態:
queued:ワーカー待ちcrawling:クロールプレビューによるページの取得中preview_ready:クロールプレビューが 選択したページをインポート または ソースの実行をキャンセル を待機中importing:アイテムのインポートとインデックス処理中syncing:ソースのドキュメントを更新中
最終状態:
completed:すべてのアイテムのインポートまたは更新、インデックス処理、アクティブ化が完了zero_results:クロールプレビューで見つかったページが 0 件failed:failureを参照canceled
failed または canceled の後は、ソースの実行を再試行 で再実行でき、ソースを同期 で新しい同期を開始できます。
Was this page helpful?
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--data '
{
"replaceExistingSelection": true,
"sourceUrls": [
"https://docs.example.com/guides/billing",
"https://docs.example.com/pricing"
]
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import"
payload = {
"replaceExistingSelection": True,
"sourceUrls": ["https://docs.example.com/guides/billing", "https://docs.example.com/pricing"]
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
replaceExistingSelection: true,
sourceUrls: ['https://docs.example.com/guides/billing', 'https://docs.example.com/pricing']
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'replaceExistingSelection' => true,
'sourceUrls' => [
'https://docs.example.com/guides/billing',
'https://docs.example.com/pricing'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import"
payload := strings.NewReader("{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import")
.header("Idempotency-Key", "<idempotency-key>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}/crawl-import")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"replaceExistingSelection\": true,\n \"sourceUrls\": [\n \"https://docs.example.com/guides/billing\",\n \"https://docs.example.com/pricing\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"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": "crawl-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"
}