ソースを更新
ソースの名前、ステータス、URI、メタデータ、またはプロバイダーパラメータを更新します。設定が変更された場合は、同期を開始することもできます。
name、status、uri、metadata、providerParameters のうち少なくとも 1 つを送信してください。expectedVersion と syncAfterUpdate だけのリクエストは拒否されます。
同期の開始と追跡の方法については、ソースの同期とスケジュール設定 を参照してください。
curl --request PATCH \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expectedVersion": 7,
"name": "Docs site (v2)",
"status": "active",
"syncAfterUpdate": true,
"uri": "https://docs.example.com/v2"
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}"
payload = {
"expectedVersion": 7,
"name": "Docs site (v2)",
"status": "active",
"syncAfterUpdate": True,
"uri": "https://docs.example.com/v2"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
expectedVersion: 7,
name: 'Docs site (v2)',
status: 'active',
syncAfterUpdate: true,
uri: 'https://docs.example.com/v2'
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}', 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}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'expectedVersion' => 7,
'name' => 'Docs site (v2)',
'status' => 'active',
'syncAfterUpdate' => true,
'uri' => 'https://docs.example.com/v2'
]),
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/{source_id}"
payload := strings.NewReader("{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}")
req, _ := http.NewRequest("PATCH", 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.patch("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}"
response = http.request(request)
puts response.read_body{
"connection_id": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"created_at": "2026-09-01T08:00: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",
"parameters": {
"url": "https://docs.example.com/v2"
},
"providerKind": "website",
"tenantId": "2f1e0d9c-8b7a-4695-8473-2a1b0c9d8e7f"
},
"name": "Docs site (v2)",
"permission_scope": [],
"status": "active",
"sync_policy": null,
"sync_workflow": {
"canceled_at": null,
"checkpoint": "queued",
"completed_at": null,
"created_at": "2026-09-06T02:00:00Z",
"cursor": null,
"execution_attempts": 0,
"failure": null,
"id": "d4c3b2a1-6f5e-4d7c-8b9a-0f1e2d3c4b5a",
"kind": "sync",
"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": null,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"state": "queued",
"updated_at": "2026-09-06T02:00:00Z"
},
"type": "web",
"updated_at": "2026-09-06T02:00:00Z",
"uri": "https://docs.example.com/v2",
"version": 8
}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 バイト以内に収める必要があります。リクエストサイズの制限 を参照してください。
- メタデータを更新
- ソース名を変更
- プロバイダーパラメータを更新
- ステータスを変更
- ソース URL を変更
null でない metadata、name、providerParameters、status、uri のうち、少なくとも 1 つを指定してください。expectedVersion と syncAfterUpdate だけでは更新になりません。
保存済みのメタデータにマージするキーです。ネストされたオブジェクトはマージされ、配列は置き換えられます。
parameters(代わりに providerParameters を使用)や認証情報を含めることはできません。datasource、pluginId、provider、providerId、providerKind は変更できません。tenantId はサービスによって上書きされます。
新しい表示名です。
1 - 200新しいステータスです。active または disabled を設定します。error と syncing は同期の実行によって設定されます。
disabled にすると、新たなスケジュール同期が行われなくなり、この更新でも同期は開始されません。すでに受け付けられた同期はキャンセルされません。
active, disabled, null true の場合、書き込み後に同期の実行をリクエストします。レスポンスには実行が sync_workflow として含まれます。この呼び出しで実行が開始されなかった場合は sync_workflow: null になります。
同期が開始されるのは、この呼び出しで uri、providerParameters、または metadata の値が変わり、かつソースの status が disabled でない場合だけです。現在と同じ値を再送信しても、同期は開始されません。ソースを変更せずに同期するには、ソースを同期 を呼び出してください。
ページリストが保存されているウェブサイトソースでは、同期によってそれらのページが更新されます。リストを変更するには、ウェブサイトのページをインポート または 選択したページをインポート を使用します。
新しい URI です。web ソースでは、認証情報が埋め込まれていない HTTP または HTTPS の URL である必要があります。metadata.parameters.url もこの値に合わせて更新されます。
1 - 4096Response
更新されたソースです。
ソースが認証情報の取得に使用する接続です。別のソースを同じ接続に紐付ける場合は、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 PATCH \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expectedVersion": 7,
"name": "Docs site (v2)",
"status": "active",
"syncAfterUpdate": true,
"uri": "https://docs.example.com/v2"
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}"
payload = {
"expectedVersion": 7,
"name": "Docs site (v2)",
"status": "active",
"syncAfterUpdate": True,
"uri": "https://docs.example.com/v2"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
expectedVersion: 7,
name: 'Docs site (v2)',
status: 'active',
syncAfterUpdate: true,
uri: 'https://docs.example.com/v2'
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}', 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}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'expectedVersion' => 7,
'name' => 'Docs site (v2)',
'status' => 'active',
'syncAfterUpdate' => true,
'uri' => 'https://docs.example.com/v2'
]),
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/{source_id}"
payload := strings.NewReader("{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}")
req, _ := http.NewRequest("PATCH", 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.patch("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/sources/{source_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"expectedVersion\": 7,\n \"name\": \"Docs site (v2)\",\n \"status\": \"active\",\n \"syncAfterUpdate\": true,\n \"uri\": \"https://docs.example.com/v2\"\n}"
response = http.request(request)
puts response.read_body{
"connection_id": "c3d4e5f6-7a8b-4c9d-8e0f-1a2b3c4d5e6f",
"created_at": "2026-09-01T08:00: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",
"parameters": {
"url": "https://docs.example.com/v2"
},
"providerKind": "website",
"tenantId": "2f1e0d9c-8b7a-4695-8473-2a1b0c9d8e7f"
},
"name": "Docs site (v2)",
"permission_scope": [],
"status": "active",
"sync_policy": null,
"sync_workflow": {
"canceled_at": null,
"checkpoint": "queued",
"completed_at": null,
"created_at": "2026-09-06T02:00:00Z",
"cursor": null,
"execution_attempts": 0,
"failure": null,
"id": "d4c3b2a1-6f5e-4d7c-8b9a-0f1e2d3c4b5a",
"kind": "sync",
"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": null,
"source_id": "6f1c2b0e-3d0b-4a5e-9f4c-1c0e6a7b8d90",
"state": "queued",
"updated_at": "2026-09-06T02:00:00Z"
},
"type": "web",
"updated_at": "2026-09-06T02:00:00Z",
"uri": "https://docs.example.com/v2",
"version": 8
}