# 4.3 Delete files

<mark style="color:red;">`DELETE`</mark> `/documentClassification/deleteFiles`

This endpoint permanently deletes one or more specific files from a batch within a document classification process.

You must provide the `classificationId`, `batchId`, and a list of `fileIds` in the request body. This action is irreversible and will remove the specified files and their associated results, without affecting the rest of the batch or classification.

Use this endpoint to precisely remove files without deleting the entire batch or classification. Separate endpoints exist for deleting entire classifications or batches.

## Server URL

```
https://api.extracta.ai/api/v1
```

## Headers

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

## Body

<table><thead><tr><th width="183">Name</th><th width="135">Type</th><th width="164">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>classificationId</code></td><td>string</td><td><code>true</code></td><td>The classification id.</td></tr><tr><td><code>batchId</code></td><td>string</td><td><code>true</code></td><td>The batch id.</td></tr><tr><td><code>fileIds</code></td><td>list&#x3C;string></td><td><code>true</code></td><td>A list of specific file ids.</td></tr></tbody></table>

## Body Example

```json
{
    "classificationId": "classificationId",
    "batchId": "batchId",
    "fileIds": ["fileId1", "fileId2", "fileId3"]
}
```

## Code Example

{% tabs %}
{% tab title="JavaScript" %}

```javascript
const axios = require('axios');

async function deleteFiles(token, classificationId, batchId, fileIds) {
    const url = "https://api.extracta.ai/api/v1/documentClassification/deleteFiles";

    try {
        const response = await axios.delete(url, {
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${token}`
            },
            data: {
                classificationId: classificationId,
                batchId: batchId,
                fileIds: fileIds
            }
        });

        return response.data;
    } catch (error) {
        throw error.response ? error.response.data : new Error('An unknown error occurred');
    }
}

async function main() {
    const token = 'apiKey';
    const classificationId = 'classificationId';
    const batchId = 'batchId';
    const fileIds = ["fileId1", "fileId2", "fileId3"];

    try {
        const response = await deleteFiles(token, classificationId, batchId, fileIds);
        console.log("Files Deleted:", response);
    } catch (error) {
        console.error("Failed to delete files:", error);
    }
}

main();
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

def delete_files(token, classification_id, batch_id, file_ids):
    url = "https://api.extracta.ai/api/v1/documentClassification/deleteFiles"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {token}"
    }
    payload = {
        "classificationId": classification_id,
        "batchId": batch_id,
        "fileIds": file_ids
    }

    try:
        response = requests.delete(url, json=payload, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        print(f"Failed to delete classification: {e}")
        return None

# Example usage
if __name__ == "__main__":
    token = "apiKey"
    classification_id = "classificationId"
    batch_id = "batchId"
    file_ids = ["fileId1", "fileId2", "fileId3"]

    response = delete_batch(token, classification_id, batch_id, file_ids)
    if response:
        print("Files Deleted:", response)
    else:
        print("Failed to delete files.")
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

function deleteFiles($token, $classificationId, $batchId, $fileIds) {
    $url = 'https://api.extracta.ai/api/v1/documentClassification/deleteFiles';

    // Initialize cURL session
    $ch = curl_init($url);

    // Prepare the payload
    $payload = json_encode([
        'classificationId' => $classificationId,
        'batchId' => $batchId,
        'fileIds' => $fileIds
    ]);

    // Set cURL options
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $token,
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    try {
        $response = curl_exec($ch);

        if (curl_errno($ch)) {
            throw new Exception('Curl error: ' . curl_error($ch));
        }

        return $response;
    } catch (Exception $e) {
        return 'Error: ' . $e->getMessage();
    } finally {
        curl_close($ch);
    }
}

// Example usage
$token = 'apiKey';
$classificationId = 'classificationId';
$batchId = 'batchId';
$fileIds = ['fileId1', 'fileId2', 'fileId3'];

try {
    $response = deleteFiles($token, $classificationId, $batchId, $fileIds);
    echo "Files Deleted: " . $response;
} catch (Exception $e) {
    echo "Failed to delete files: " . $e->getMessage();
}

?>
```

{% endtab %}
{% endtabs %}

## Responses

{% tabs %}
{% tab title="200" %}

```json
{
    "status": "success",
    "message": "Files deleted"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "status": "success",
    "message": "Files deleted"
}
```

{% endtab %}

{% tab title="500" %}

```json
{
    "status": "error",
    "message": "Internal server error"
}
```

{% endtab %}
{% endtabs %}
