更新数据源
更新数据源的名称、状态、URI、元数据或提供商参数;配置有变化时,可同时启动一次同步。
至少传入 name、status、uri、metadata、providerParameters 中的一项。只传 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
Path Parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。
Body
标记为 nullable 的可选字段,传 null 等同于省略。
规范化后的请求不得超过 262,144 个 UTF-8 字节。参见 请求大小限制。
- 更新元数据
- 重命名数据源
- 更新提供商参数
- 更改状态
- 更改数据源 URL
至少提供一个非 null 的 metadata、name、providerParameters、status 或 uri。只有 expectedVersion 和 syncAfterUpdate 不构成更新。
要合并进已存储元数据的键。嵌套对象会合并,数组会整体替换。
不得包含 parameters(改用 providerParameters)或凭据。datasource、pluginId、provider、providerId 和 providerKind 不可更改。服务端会覆盖 tenantId。
新的显示名称。
1 - 200新状态。可设为 active 或 disabled。error 和 syncing 由同步运行设置。
disabled 会阻止新的定时同步,也会阻止本次更新启动同步,但不会取消已受理的同步。
active, disabled, null 新的 URI。web 数据源的 URI 必须是 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
}