Delete a file from a knowledge folder
curl --request DELETE \
--url https://api.langdock.com/knowledge/{folderId}/{attachmentId} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.langdock.com/knowledge/{folderId}/{attachmentId}"
headers = {"Authorization": "Bearer <token>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.langdock.com/knowledge/{folderId}/{attachmentId}', 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}/{attachmentId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/knowledge/{folderId}/{attachmentId}"
req, _ := http.NewRequest("DELETE", url, nil)
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.delete("https://api.langdock.com/knowledge/{folderId}/{attachmentId}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}/{attachmentId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyKnowledge Folder API
Delete Attachment from Knowledge Folder
Remove a file from a Knowledge base
DELETE
/
knowledge
/
{folderId}
/
{attachmentId}
Delete a file from a knowledge folder
curl --request DELETE \
--url https://api.langdock.com/knowledge/{folderId}/{attachmentId} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.langdock.com/knowledge/{folderId}/{attachmentId}"
headers = {"Authorization": "Bearer <token>"}
response = requests.delete(url, headers=headers)
print(response.text)const options = {method: 'DELETE', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.langdock.com/knowledge/{folderId}/{attachmentId}', 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}/{attachmentId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/knowledge/{folderId}/{attachmentId}"
req, _ := http.NewRequest("DELETE", url, nil)
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.delete("https://api.langdock.com/knowledge/{folderId}/{attachmentId}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}/{attachmentId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_bodyDeletes a file (attachment) from a Knowledge base. This removes the file and all associated embeddings, making the content no longer searchable.
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
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
folderId | string | Yes | The ID of the Knowledge base |
attachmentId | string | Yes | The ID of the attachment to delete |
Examples
Delete with cURL
curl -X DELETE "https://api.langdock.com/knowledge/{folderId}/{attachmentId}" \
-H "Authorization: Bearer YOUR_API_KEY"
Delete with JavaScript
const axios = require("axios");
async function deleteAttachment(folderId, attachmentId) {
const response = await axios.delete(
`https://api.langdock.com/knowledge/${folderId}/${attachmentId}`,
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
},
}
);
return response.data;
}
// Example usage
try {
const result = await deleteAttachment("folder_abc123", "att_xyz789");
console.log("Attachment deleted:", result.message);
} catch (error) {
console.error("Failed to delete:", error.response?.data?.message);
}
Bulk Delete Example
async function deleteMultipleAttachments(folderId, attachmentIds) {
const results = await Promise.allSettled(
attachmentIds.map((id) => deleteAttachment(folderId, id))
);
const succeeded = results.filter((r) => r.status === "fulfilled").length;
const failed = results.filter((r) => r.status === "rejected").length;
console.log(`Deleted ${succeeded} files, ${failed} failed`);
return results;
}
Response Format
Success Response (200 OK)
{
status: "success";
message: "Attachment deleted";
}
Example Response
{
"status": "success",
"message": "Attachment deleted"
}
Error Handling
try {
const response = await deleteAttachment(folderId, attachmentId);
} catch (error) {
if (error.response) {
switch (error.response.status) {
case 400:
console.error("Invalid request:", error.response.data.message);
break;
case 401:
console.error("Invalid or missing API key");
break;
case 403:
console.error("API key does not have access to this Knowledge base");
break;
case 404:
console.error("Knowledge base or attachment not found");
break;
case 429:
console.error("Rate limit exceeded");
break;
case 500:
console.error("Server error");
break;
}
}
}
Important Notes
Deletion is permanent. The file and all associated embeddings will be removed and cannot be recovered.
- The attachment must belong to the specified Knowledge base
- The Knowledge base must be shared with your API key
- Deleting an attachment removes it from search results immediately
- Embeddings associated with the attachment are also deleted
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.
Was this page helpful?