> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langdock.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete Attachment API

> Einen hochgeladenen Anhang anhand der ID löschen

<Info>
  **⚠️ Du nutzt unsere API in einem Dedicated Deployment?** Ersetze einfach `api.langdock.com` durch die Base URL deines Deployments: **`<deployment-url>/api/public`**
</Info>

Lösche einen Anhang anhand seiner ID. Der Anhang muss zum gleichen Workspace wie der API-Schlüssel gehören und entweder vom Ersteller des API-Schlüssels erstellt worden sein oder zu einer Wissensdatenbank gehören, die mit dem API-Schlüssel geteilt ist.

<Info>
  Erfordert einen API-Schlüssel mit dem `KNOWLEDGE_FOLDER_API` Scope. Du kannst API-Schlüssel in deinen [Workspace
  Einstellungen](https://app.langdock.com/settings/workspace/products/api) erstellen.
</Info>

## Anforderungsformat

Sende die Anhangs-ID im Request-Body als JSON.

| Parameter      | Typ    | Erforderlich | Beschreibung                       |
| -------------- | ------ | ------------ | ---------------------------------- |
| `attachmentId` | string | Ja           | Die UUID des zu löschenden Anhangs |

## Antwortformat

```typescript theme={null}
{
  success: true;
  message: string;
  attachmentId: string;
}
```

## Beispiel

```javascript theme={null}
const axios = require("axios");

async function deleteAttachment(attachmentId) {
  const response = await axios.delete(
    "https://api.langdock.com/attachment/v1/delete",
    {
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
      },
      data: { attachmentId },
    }
  );

  console.log(response.data);
  // {
  //   success: true,
  //   message: "Attachment deleted successfully",
  //   attachmentId: "550e8400-e29b-41d4-a716-446655440000"
  // }
}
```

## Fehlerbehandlung

```javascript theme={null}
try {
  await deleteAttachment("550e8400-e29b-41d4-a716-446655440000");
} catch (error) {
  if (error.response) {
    switch (error.response.status) {
      case 400:
        console.error("Ungültiger Request-Body:", error.response.data.message);
        break;
      case 401:
        console.error("Ungültiger API-Schlüssel");
        break;
      case 403:
        console.error("API-Schlüssel hat keinen Zugriff auf diesen Anhang");
        break;
      case 404:
        console.error("Anhang nicht gefunden");
        break;
      case 500:
        console.error("Server-Fehler");
        break;
    }
  }
}
```

<Warning>
  Ein gelöschter Anhang kann nicht mehr in Agent-Konversationen referenziert oder über die API wiederhergestellt werden.
</Warning>

<Info>
  Langdock blockiert bewusst Browser-basierte Anfragen, um deinen API-Schlüssel zu schützen und die Sicherheit deiner Anwendungen zu gewährleisten. Weitere Informationen findest du in unserem Guide zu [Best Practices für API-Schlüssel](/de/admin/ai-adoption-and-rollout/best-practices/api-key-best-practices).
</Info>


## OpenAPI

````yaml DELETE /attachment/v1/delete
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
security:
  - bearerAuth: []
paths:
  /attachment/v1/delete:
    delete:
      tags:
        - Attachments
      summary: Delete an attachment
      description: >-
        Soft-deletes an attachment by ID. The attachment must be created by the
        API key's creator or belong to a Knowledge base shared with the API key.
      operationId: deleteAttachment
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - attachmentId
              properties:
                attachmentId:
                  type: string
                  format: uuid
                  description: The ID of the attachment to delete
      responses:
        '200':
          description: Attachment deleted successfully
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - message
                  - attachmentId
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Attachment deleted successfully
                  attachmentId:
                    type: string
                    format: uuid
                    description: The ID of the deleted attachment
        '400':
          description: Invalid request body
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  errors:
                    type: array
                    items: {}
        '401':
          description: Invalid API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
        '403':
          description: API key does not have access to this attachment
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '404':
          description: Attachment not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````