Skip to main content
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>'
Using our API via a dedicated deployment? Just replace api.langdock.com with your deployment’s base URL: <deployment-url>/api/public
Deletes a file (attachment) from a knowledge folder. This removes the file and all associated embeddings, making the content no longer searchable.
Requires an API key with the KNOWLEDGE_FOLDER_API scope. The knowledge folder must be shared with the API key. See Share Knowledge Folders with the API for setup instructions.

Request Format

Path Parameters

ParameterTypeRequiredDescription
folderIdstringYesThe ID of the knowledge folder
attachmentIdstringYesThe 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 folder");
        break;
      case 404:
        console.error("Knowledge folder 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 folder
  • The knowledge folder 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.

Authorizations

Authorization
string
header
required

API key as Bearer token. Format "Bearer YOUR_API_KEY"

Path Parameters

folderId
string
required

The ID of the knowledge folder

attachmentId
string
required

The ID of the attachment to delete

Response

200

Attachment deleted successfully