数据源
更新数据源
更新数据源的名称、状态、URI、元数据或提供商参数;配置有变化时,可同时启动一次同步。
至少传入 name、status、uri、metadata、providerParameters 中的一项。只传 expectedVersion 和 syncAfterUpdate 的请求会被拒绝。
如何启动和跟踪同步,详见 同步数据源与定时同步。
PATCH
/
knowledge-fs
/
spaces
/
{knowledge_base_id}
/
sources
/
{source_id}
更新数据源
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 密钥(快速开始)。
API 密钥应保存在服务端,切勿嵌入客户端代码。缺失或无效的密钥会返回 HTTP 401(unauthorized)。
Body
application/json
标记为 nullable 的可选字段,传 null 等同于省略。
规范化后的请求不得超过 262,144 个 UTF-8 字节。参见 请求大小限制。
- 更新元数据
- 重命名数据源
- 更新提供商参数
- 更改状态
- 更改数据源 URL
至少提供一个非 null 的 metadata、name、providerParameters、status 或 uri。只有 expectedVersion 和 syncAfterUpdate 不构成更新。
所选数据源定义的参数。此字段会整体替换已存储的 metadata.parameters 对象,因此需包含所有要保留的值。值可以是布尔值、有限数值或字符串。疑似凭据的键会被拒绝。
如果 获取数据源 未返回完整的非敏感参数,而你也不清楚该数据源的参数约定,改在 Dify 中配置数据源。
Was this page helpful?
⌘I
更新数据源
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
}