ソースを作成
ソースの接続一覧を取得 で見つけた既存の接続を通じて読み取るソースを追加します。クロールやインポートは行われません。
成功した作成リクエストを繰り返すと、別のソースが作成されます。一意の metadata.client_request_id を付け、ソース ID を受け取るまで保持してください。
web ソースにデータを取り込むには、ウェブサイトのクロールをプレビュー または ウェブサイトのページをインポート を呼び出してください。connector ソースでは ソースのアイテムをインポート を呼び出します。手順については、ソースの追加 を参照してください。
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"connectionId": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website"
},
"name": "Docs site",
"permissionScope": [],
"status": "disabled",
"type": "web",
"uri": "https://docs.example.com"
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources"
payload = {
"connectionId": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website"
},
"name": "Docs site",
"permissionScope": [],
"status": "disabled",
"type": "web",
"uri": "https://docs.example.com"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
connectionId: 'c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f',
metadata: {client_request_id: 'source-20260907-0001', providerKind: 'website'},
name: 'Docs site',
permissionScope: [],
status: 'disabled',
type: 'web',
uri: 'https://docs.example.com'
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources', 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",
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([
'connectionId' => 'c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f',
'metadata' => [
'client_request_id' => 'source-20260907-0001',
'providerKind' => 'website'
],
'name' => 'Docs site',
'permissionScope' => [
],
'status' => 'disabled',
'type' => 'web',
'uri' => 'https://docs.example.com'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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"
payload := strings.NewReader("{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}"
response = http.request(request)
puts response.read_body{
"connection_id": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"created_at": "2026-09-06T01:30:00Z",
"credential_configured": null,
"id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_synced_at": null,
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website",
"tenantId": "2f1e0d9c-8b7a-4695-8473-2a1b0c9d8e7f"
},
"name": "Docs site",
"permission_scope": [],
"status": "disabled",
"sync_policy": null,
"sync_workflow": null,
"type": "web",
"updated_at": "2026-09-06T01:30:00Z",
"uri": "https://docs.example.com",
"version": 1
}Authorizations
すべてのリクエストは API キーで認証します:Authorization: Bearer {API_KEY}。アプリのエンドポイントにはアプリの API キーを、ナレッジのエンドポイントにはナレッジベースの API キーを使用します(Dify API クイックスタート)。
キーはサーバーサイドで保管し、クライアントコードには決して埋め込まないでください。キーが欠落または無効なリクエストは HTTP 401(unauthorized)で失敗します。
Path Parameters
ナレッジベース ID です。ナレッジベースの API アクセス ダイアログに表示されるサービス API エンドポイントの最後のセグメント(…/knowledge-fs/spaces/<knowledge base ID>)です。アドレスバーでは /datasets/new/ の後のセグメントです。
Body
nullable と記されたオプションフィールドでは、null は省略と同じ扱いになります。
正規化後のリクエストは、UTF-8 で 262,144 バイト以内に収める必要があります。リクエストサイズの制限 を参照してください。
表示名です。
1 - 200ウェブサイトのクロールには web を、オンラインドキュメントまたはオンラインドライブのプロバイダーには connector を指定します(metadata.providerKind も設定します)。upload と object-storage は、Dify がデータを取り込むソース用の値です。
connector, object-storage, upload, web web ではクロールのルート URL を指定します。connector では、Dify が書き込む値に合わせて connector://<connectionId> を指定します。
1 - 4096ソースが読み取りに使う認証情報を提供する接続です。このナレッジベースに属し、active である必要があります。ソースの接続一覧を取得 の id から取得します。
プロバイダーの設定と、機密でない独自のメタデータです。作成時のレスポンスが失われた場合にこのソースを識別できるよう、一意の client_request_id を付けてください。この値はソースとともに返されますが、API は一意性を強制せず、重複したリクエストも排除しません。
providerKind には接続の configuration.providerKind を設定し、それに合ったソースの type を選んでください。接続から取得される設定は、ソースのレスポンスに含まれない場合があります。
既存のソースのレスポンスをもとに metadata を組み立てる場合は、__knowledgeFs で始まるフィールド、credentials、parameters オブジェクトを除いてください。credentialId がある場合は、Dify が保持する認証情報を指します。
空にするか省略してください。空のリストのみ受け付けます。
disabled にすると、スケジュール同期が一時停止します。
active, disabled, null Response
作成されたソースです。
ソースが認証情報の取得に使用する接続です。別のソースを同じ接続に紐付ける場合は、connectionId として渡します。紐付けられていない場合は null です。
作成日時(ISO 8601)です。
ソースが独自の認証情報の参照を保持している場合は true です。接続に紐付けられたソースのように参照を保持していない場合は null です。
ソース ID です。
ナレッジベースの内部 ID です。パスのナレッジベース ID とは異なります。
プロバイダーの設定と、サーバーが管理する同期データまたはページ選択データです。プロバイダーの識別子や parameters が含まれる場合があります。接続側で管理される設定は、ここに含まれるとは限りません。認証情報に類するキーは除去されます。別のソースを作成する際に、このオブジェクト全体をコピーしないでください。
表示名です。
このソースを読み取るために必要なコンテンツのアクセス範囲です。空のリストの場合、ナレッジベース内でのコンテンツの制限は追加されません。ナレッジベースの認可は引き続き適用されます。
web(ウェブサイトのクロール)、connector(オンラインドキュメントまたはオンラインドライブ)、upload、object-storage のいずれかです。
connector ソースでは、metadata.providerKind は online-document または online-drive です。web ソースでは website です。
upload と object-storage のソースには、Dify が内容を追加します。
最終更新日時(ISO 8601)です。
web ソースでは、クロールのルート URL です。Dify で作成されたコネクタソースでは connector://<connection_id> です。
Was this page helpful?
curl --request POST \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"connectionId": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website"
},
"name": "Docs site",
"permissionScope": [],
"status": "disabled",
"type": "web",
"uri": "https://docs.example.com"
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources"
payload = {
"connectionId": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website"
},
"name": "Docs site",
"permissionScope": [],
"status": "disabled",
"type": "web",
"uri": "https://docs.example.com"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
connectionId: 'c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f',
metadata: {client_request_id: 'source-20260907-0001', providerKind: 'website'},
name: 'Docs site',
permissionScope: [],
status: 'disabled',
type: 'web',
uri: 'https://docs.example.com'
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources', 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",
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([
'connectionId' => 'c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f',
'metadata' => [
'client_request_id' => 'source-20260907-0001',
'providerKind' => 'website'
],
'name' => 'Docs site',
'permissionScope' => [
],
'status' => 'disabled',
'type' => 'web',
'uri' => 'https://docs.example.com'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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"
payload := strings.NewReader("{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}")
req, _ := http.NewRequest("POST", url, payload)
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")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"connectionId\": \"c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f\",\n \"metadata\": {\n \"client_request_id\": \"source-20260907-0001\",\n \"providerKind\": \"website\"\n },\n \"name\": \"Docs site\",\n \"permissionScope\": [],\n \"status\": \"disabled\",\n \"type\": \"web\",\n \"uri\": \"https://docs.example.com\"\n}"
response = http.request(request)
puts response.read_body{
"connection_id": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"created_at": "2026-09-06T01:30:00Z",
"credential_configured": null,
"id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"knowledge_space_id": "0a9d3c2e-5b6f-4e1a-8c7d-2f3e4a5b6c7d",
"last_synced_at": null,
"metadata": {
"client_request_id": "source-20260907-0001",
"providerKind": "website",
"tenantId": "2f1e0d9c-8b7a-4695-8473-2a1b0c9d8e7f"
},
"name": "Docs site",
"permission_scope": [],
"status": "disabled",
"sync_policy": null,
"sync_workflow": null,
"type": "web",
"updated_at": "2026-09-06T01:30:00Z",
"uri": "https://docs.example.com",
"version": 1
}