创建数据源
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_bodyAuthorizations
Path Parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。
Body
标记为 nullable 的可选字段,传 null 等同于省略。
规范化后的请求不得超过 262,144 个 UTF-8 字节。参见 请求大小限制。
显示名称。
1 - 200网站抓取传 web,在线文档或在线云盘提供商传 connector(并设置 metadata.providerKind)。upload 和 object-storage 用于由 Dify 填充内容的数据源。
connector, object-storage, upload, web web 数据源填抓取的根 URL。connector 数据源填 connector://<connectionId>,与 Dify 写入的格式一致。
1 - 4096提供商设置,以及你自己的非敏感元数据。添加唯一的 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