# Delete

Permanently deletes a document and all associated data that was created by the v2 parse, extract, or split endpoints. This includes the document record, the uploaded PDF file in storage, and the cached parse results.

<mark style="color:green;">`POST`</mark> `https://pdf.ai/api/v2/delete`

{% hint style="warning" %}
This endpoint only works for documents created via v2 parse, extract, or split endpoints.

Deletion is permanent and cannot be undone.
{% endhint %}

#### Sample Code

Below are examples of how to use the `delete` endpoint with different programming languages.

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

```shellscript
curl -X POST https://pdf.ai/api/v2/delete \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"docId": "your-document-id"}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://pdf.ai/api/v2/delete"
headers = {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json"
}

data = {"docId": "your-document-id"}

response = requests.post(url, headers=headers, json=data)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

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

axios.post('https://pdf.ai/api/v2/delete', 
  { docId: 'your-document-id' },
  {
    headers: {
      'X-API-Key': 'YOUR_API_KEY',
      'Content-Type': 'application/json'
    }
  }
).then(response => {
  console.log(response.data);
});
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://pdf.ai/api/v2/delete";
$apiKey = "YOUR_API_KEY";

$data = json_encode(["docId" => "your-document-id"]);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "X-API-Key: $apiKey",
    "Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>
```

{% endtab %}
{% endtabs %}

Please replace placeholders like `<YOUR_API_Key>` with actual values.

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-Key<mark style="color:red;">\*</mark> | string | \<API-Key>  |

#### Request Format

Content-Type: application/json

#### Request Parameters

| Parameter | Type   | Required | Description                                        |
| --------- | ------ | -------- | -------------------------------------------------- |
| docId     | string | Yes      | Document ID returned from Parse, Extract, or Split |

#### Response format

{% tabs %}
{% tab title="Success Response (200)" %}
{% code overflow="wrap" %}

```json
{
  "success": true,
  "message": "Document and all associated data deleted successfully"
}
```

{% endcode %}
{% endtab %}

{% tab title="400 Bad Request - Missing docId " %}

```json
{ "error": "docId is required" }
```

{% endtab %}

{% tab title="400 Bad Request - Not a v2 document" %}

```json
{ 
  "error": "This document was not created by v2 parse, extract, or split endpoints",
  "hint": "Use the v1 delete endpoint for other documents"
}
```

{% endtab %}

{% tab title="404 Not Found" %}
{ "error": "Invalid API key" }
{% endtab %}

{% tab title="401 Unauthorized" %}

{% endtab %}
{% endtabs %}

#### Credit Usage

Free - no API credits are charged for delete operations.
