Update a file in a knowledge folder
curl --request PATCH \
--url https://api.langdock.com/knowledge/{folderId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form 'url=<string>' \
--form 'attachmentId=<string>'import requests
url = "https://api.langdock.com/knowledge/{folderId}"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"url": "<string>",
"attachmentId": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.patch(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('url', '<string>');
form.append('attachmentId', '<string>');
const options = {method: 'PATCH', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.langdock.com/knowledge/{folderId}', 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.langdock.com/knowledge/{folderId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$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.langdock.com/knowledge/{folderId}"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.langdock.com/knowledge/{folderId}")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"message": "The file \"updated-report.pdf\" is declared as a PDF but its content does not start with the expected PDF header.",
"code": "BAD_REQUEST"
}{
"message": "The provided API key is invalid."
}{
"message": "Knowledge folder not shared with this API key. Please share the folder with the API key in the Langdock App to upload or update files.",
"code": "FORBIDDEN"
}{
"message": "Attachment with ID '550e8400-e29b-41d4-a716-446655440000' not found in this knowledge folder.",
"code": "NOT_FOUND"
}{
"message": "Upload request timed out. Please try again with a smaller file or check your connection.",
"code": "REQUEST_TIMEOUT"
}{
"message": "File size exceeds the maximum allowed size of 256MB. Please upload a smaller file.",
"code": "PAYLOAD_TOO_LARGE"
}{
"message": "You have exceeded the maximum number of requests per minute (50)",
"code": "TOO_MANY_REQUESTS"
}{
"message": "Internal server error"
}{
"message": "Storage capacity exceeded. Please contact your administrator.",
"code": "SERVICE_UNAVAILABLE"
}Knowledge Folder API
Update Attachment in Knowledge Folder
Replace an existing file in a Knowledge base with a new version
PATCH
/
knowledge
/
{folderId}
Update a file in a knowledge folder
curl --request PATCH \
--url https://api.langdock.com/knowledge/{folderId} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form 'url=<string>' \
--form 'attachmentId=<string>'import requests
url = "https://api.langdock.com/knowledge/{folderId}"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"url": "<string>",
"attachmentId": "<string>"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.patch(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('url', '<string>');
form.append('attachmentId', '<string>');
const options = {method: 'PATCH', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.langdock.com/knowledge/{folderId}', 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.langdock.com/knowledge/{folderId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$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.langdock.com/knowledge/{folderId}"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.langdock.com/knowledge/{folderId}")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"attachmentId\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"message": "The file \"updated-report.pdf\" is declared as a PDF but its content does not start with the expected PDF header.",
"code": "BAD_REQUEST"
}{
"message": "The provided API key is invalid."
}{
"message": "Knowledge folder not shared with this API key. Please share the folder with the API key in the Langdock App to upload or update files.",
"code": "FORBIDDEN"
}{
"message": "Attachment with ID '550e8400-e29b-41d4-a716-446655440000' not found in this knowledge folder.",
"code": "NOT_FOUND"
}{
"message": "Upload request timed out. Please try again with a smaller file or check your connection.",
"code": "REQUEST_TIMEOUT"
}{
"message": "File size exceeds the maximum allowed size of 256MB. Please upload a smaller file.",
"code": "PAYLOAD_TOO_LARGE"
}{
"message": "You have exceeded the maximum number of requests per minute (50)",
"code": "TOO_MANY_REQUESTS"
}{
"message": "Internal server error"
}{
"message": "Storage capacity exceeded. Please contact your administrator.",
"code": "SERVICE_UNAVAILABLE"
}Updates an existing file (attachment) in a Knowledge base by replacing it with a new version. The old file is removed and the new file is processed and embedded.
File size limits depend on the file type: 10 MB for plain text, Markdown, JSON, and VTT files; 30 MB for XML files; and 256 MB for other supported document types. See the supported file types reference for supported formats.
Before You Start
- API key scope: Requires an API key with the
KNOWLEDGE_FOLDER_APIscope. The API key itself needs the Editor role on the Knowledge base. See Share Knowledge bases with the API for setup instructions. - Knowledge bases: The Knowledge Folder API manages resources that appear as Knowledge bases in the Library.
Base URL
https://api.langdock.com
Dedicated deploymentsReplace
api.langdock.com with <your-deployment-url>/api/public in all requests.Request Format
This endpoint acceptsmultipart/form-data requests with the file attached.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
folderId | string | Yes | The ID of the Knowledge base |
Form Fields
| Field | Type | Required | Description |
|---|---|---|---|
attachmentId | string | Yes | The ID of the attachment to update |
file | file | Yes | The new file to upload. See size limits below. |
url | string | No | URL shown to users when this file is used in an answer |
Examples
Update with cURL
curl -X PATCH "https://api.langdock.com/knowledge/{folderId}" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "attachmentId=att_abc123def456" \
-F "file=@/path/to/new-document.pdf"
Update with JavaScript
const FormData = require("form-data");
const fs = require("fs");
const axios = require("axios");
async function updateAttachment(folderId, attachmentId, filePath) {
const form = new FormData();
form.append("attachmentId", attachmentId);
form.append("file", fs.createReadStream(filePath));
const response = await axios.patch(
`https://api.langdock.com/knowledge/${folderId}`,
form,
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
...form.getHeaders(),
},
}
);
return response.data;
}
// Example usage
try {
const result = await updateAttachment(
"folder_abc123",
"att_xyz789",
"/path/to/updated-report.pdf"
);
console.log("Attachment updated:", result);
} catch (error) {
console.error("Failed to update:", error.response?.data?.message);
}
Update with Source URL
const FormData = require("form-data");
const fs = require("fs");
const axios = require("axios");
async function updateAttachmentWithUrl(folderId, attachmentId, filePath, sourceUrl) {
const form = new FormData();
form.append("attachmentId", attachmentId);
form.append("file", fs.createReadStream(filePath));
form.append("url", sourceUrl);
const response = await axios.patch(
`https://api.langdock.com/knowledge/${folderId}`,
form,
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
...form.getHeaders(),
},
}
);
return response.data;
}
Response Format
Success Response (200 OK)
{
status: "success";
result: {
id: string; // Unique attachment ID
name: string; // Original filename
mimeType: string; // MIME type of the file
createdAt: string; // ISO 8601 timestamp
updatedAt: string; // ISO 8601 timestamp
url: string | null; // Source URL if provided
};
}
Example Response
{
"status": "success",
"result": {
"id": "att_abc123def456",
"name": "updated-report.pdf",
"mimeType": "application/pdf",
"createdAt": "2025-01-15T10:30:00.000Z",
"updatedAt": "2025-01-20T14:45:00.000Z",
"url": null
}
}
File Validation Response (400 Bad Request)
If the replacement file fails validation, the API returns the reason inmessage:
{
"message": "The file \"updated-report.pdf\" is declared as a PDF but its content does not start with the expected PDF header.",
"code": "BAD_REQUEST"
}
Error Handling
try {
const response = await updateAttachment(folderId, attachmentId, filePath);
} catch (error) {
if (error.response) {
console.error(error.response.data.message ?? "Update failed");
}
}
| Status | Meaning |
|---|---|
400 | Invalid request or file validation failure |
401 | Invalid or missing API key |
403 | API key does not have access to the Knowledge base |
404 | Knowledge base or attachment not found |
408 | Upload timed out |
413 | File exceeds the size limit |
429 | Rate limit exceeded |
500 | Unexpected server error |
503 | Storage capacity exceeded |
Processing Status
After updating, the new file is processed asynchronously. Use the Retrieve Files endpoint to check processing status. ThesyncStatus field indicates the current state:
UPLOADING- File is being uploadedUPLOADED- File is uploaded and queued for processingEXTRACTING- Text is being extracted from the fileEMBEDDING- Embeddings are being generatedSYNCED- File is ready for searchACTION_FAILED,EXTRACTION_FAILED,EMBEDDING_FAILED,TIMEOUT- Processing failed
Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on API Key Best Practices.
Authorizations
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Path Parameters
The ID of the knowledge folder
Body
multipart/form-data
Response
Attachment updated successfully
Was this page helpful?