更新文档元数据
将键合并到文档的 user_metadata 中,并返回更新后的文档。与此路径上的其他操作不同,它接收的是文档 ID,而不是文档文件 ID。
将文档的 row_version 作为 expectedRowVersion 发送。更新前先读取文档;收到 409 时,重新读取后再次发送。
curl --request PATCH \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expectedRowVersion": 4,
"patch": {
"owner": "billing-team",
"review_date": "2027-03-01T00:00:00Z"
}
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_id}"
payload = {
"expectedRowVersion": 4,
"patch": {
"owner": "billing-team",
"review_date": "2027-03-01T00:00:00Z"
}
}
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({
expectedRowVersion: 4,
patch: {owner: 'billing-team', review_date: '2027-03-01T00:00:00Z'}
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_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}/documents/{document_file_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([
'expectedRowVersion' => 4,
'patch' => [
'owner' => 'billing-team',
'review_date' => '2027-03-01T00:00:00Z'
]
]),
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}/documents/{document_file_id}"
payload := strings.NewReader("{\n \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\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}/documents/{document_file_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_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 \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\n}"
response = http.request(request)
puts response.read_body{
"active": {
"activated_at": "2026-10-20T08:16:05Z",
"content_hash": "4f7c2d9a1b3e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4",
"created_at": "2026-10-20T08:15:42Z",
"document_asset_id": "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b",
"document_asset_version": 1,
"document_id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"mime_type": "application/pdf",
"revision": 2,
"size_bytes": 482113,
"state": "active"
},
"active_revision": 2,
"created_at": "2026-09-03T10:02:11Z",
"disabled_at": null,
"disabled_by_subject_id": null,
"enabled": true,
"id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"latest_task": null,
"provider_item_id": null,
"row_version": 5,
"source_id": null,
"status": "ready",
"title": "handbook.pdf",
"updated_at": "2026-10-21T02:40:13Z",
"user_metadata": {
"owner": "billing-team",
"product_line": "billing",
"review_date": "2027-03-01T00:00:00Z"
}
}Authorizations
Path Parameters
知识库 ID:即知识库 API 访问 对话框中所示服务 API 端点的最后一段(…/knowledge-fs/spaces/<knowledge base ID>),也是地址栏中 /datasets/new/ 之后的那一段。
Body
规范化后的请求不得超过 131,072 个 UTF-8 字节。参见 请求大小限制。
要合并到 user_metadata 中的键:
- 键带有值时,设置该键。
- 键的值为
null时,删除该键。 - 未传入的键保持不变。
每个键对应一个元数据字段名,使用小写蛇形命名(snake case)。该字段必须已存在:先在 Dify 中创建。值必须与字段类型匹配:string 类型为字符串,number 类型为有限数值,time 类型为 UTC 时间戳,例如 2026-12-01T00:00:00Z。
使用保留键会返回 400:activeRevision、contentHash、documentAssetId、documentAssetVersion、mimeType、provenance、providerItemId、sourceId、system、systemMetadata、tenantId、__knowledgeFs,以及以 system.、provenance. 或 __knowledgeFs. 开头的键。
Response
更新后的文档。下次更新时发送其中的 row_version;此响应中的 latest_task 始终为 null。
生效修订版本的编号。没有生效的修订版本时为 null。
文档创建时间,ISO 8601 格式。
在 Dify 中禁用该文档的时间,ISO 8601 格式。
禁用该文档的操作者的内部 ID。调用此 API 时无需使用。
文档 ID。文档内容更新后保持不变。
知识库的内部 ID,并非路径中的知识库 ID。
文档的来源数据源。上传的文件为 null。
pending(尚无生效的修订版本)、ready(已有修订版本生效)、failed(首个修订版本索引失败,且没有生效的修订版本)或 deleting。ready 的文档在后续修订版本失败时仍保持 ready。
文档标题。
文档最后变更时间,ISO 8601 格式。
Was this page helpful?
curl --request PATCH \
--url https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"expectedRowVersion": 4,
"patch": {
"owner": "billing-team",
"review_date": "2027-03-01T00:00:00Z"
}
}
'import requests
url = "https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_id}"
payload = {
"expectedRowVersion": 4,
"patch": {
"owner": "billing-team",
"review_date": "2027-03-01T00:00:00Z"
}
}
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({
expectedRowVersion: 4,
patch: {owner: 'billing-team', review_date: '2027-03-01T00:00:00Z'}
})
};
fetch('https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_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}/documents/{document_file_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([
'expectedRowVersion' => 4,
'patch' => [
'owner' => 'billing-team',
'review_date' => '2027-03-01T00:00:00Z'
]
]),
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}/documents/{document_file_id}"
payload := strings.NewReader("{\n \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\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}/documents/{document_file_id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{api_base_url}/knowledge-fs/spaces/{knowledge_base_id}/documents/{document_file_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 \"expectedRowVersion\": 4,\n \"patch\": {\n \"owner\": \"billing-team\",\n \"review_date\": \"2027-03-01T00:00:00Z\"\n }\n}"
response = http.request(request)
puts response.read_body{
"active": {
"activated_at": "2026-10-20T08:16:05Z",
"content_hash": "4f7c2d9a1b3e5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4",
"created_at": "2026-10-20T08:15:42Z",
"document_asset_id": "6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b",
"document_asset_version": 1,
"document_id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"mime_type": "application/pdf",
"revision": 2,
"size_bytes": 482113,
"state": "active"
},
"active_revision": 2,
"created_at": "2026-09-03T10:02:11Z",
"disabled_at": null,
"disabled_by_subject_id": null,
"enabled": true,
"id": "2f6b8d1a-7c3e-4a5b-9d0e-1f2a3b4c5d6e",
"knowledge_space_id": "9b2e5b7a-3c1d-4e2f-8a9b-1c2d3e4f5a6b",
"latest_task": null,
"provider_item_id": null,
"row_version": 5,
"source_id": null,
"status": "ready",
"title": "handbook.pdf",
"updated_at": "2026-10-21T02:40:13Z",
"user_metadata": {
"owner": "billing-team",
"product_line": "billing",
"review_date": "2027-03-01T00:00:00Z"
}
}