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

# 6. Folder Deletion

> [!WARNING]
>
> You are viewing the documentation of release 26.1, which is no longer the current one. [Go to the documentation of the current release 26.2](https://developers.circularo.com/).

## Folder Deletion

This scenario demonstrates how to delete folders and their contents in the Circularo platform. Folder deletion is a powerful operation that removes both the folder structure and all documents contained within it.

**Key features:**

* Delete folders and all their contents in a single operation
* Permanently remove folder hierarchies when no longer needed
* Clean up organizational structures efficiently
* Remove both the folder and all documents it contains

### Prerequisites

Before deleting folders, you need:

* A valid authentication token (see the "Authentication & Security" section for details)
* The folder ID of the folder you want to delete
* Edit permissions for the folder and all documents within it
* Careful consideration, as folder deletion cannot be undone when using hard delete

> [!WARNING]
>
> Folder deletion is a permanent operation when using the hardDelete option. All documents within the folder will also be permanently deleted. Make sure you have appropriate backups before proceeding.

## Step 1 - Delete a folder and its contents

This endpoint deletes a folder and all documents contained within it. In Circularo, folders are treated as special document types, so the deletion is performed using the document deletion endpoint.

* The **documents** array contains the folder ID to delete
* The **hardDelete** parameter set to true permanently removes the folder and its contents
* All documents within the folder are also deleted in the same operation
* Nested folders within the target folder are also removed recursively

> [!WARNING]
>
> The user must have edit permissions for the folder and all documents within it to successfully delete the folder.

**Endpoint**

```http theme={null}
DELETE /documents
```

**Request**

```http theme={null}
DELETE /documents?token=nPW6zBjwrlnEDWrs03EJySnBcf9bL3dXnDL648U2Kj3nsikUZ8PZs8yLHhw4WySp&hardDelete=true

Content-Type: application/json

{
  "documents": [
    {
      "id": "d29740a2-2cb4-4df6-b178-209ed3cb98f2"  //ID of the folder to delete
    }
  ]
}
```

**Response**

```json theme={null}
{
  "errors": false,
  "count": 1,
  "items": []
}
```

The folder and all its contents have been successfully deleted.

* The folder structure has been removed from the system
* All documents contained within the folder have been deleted

***

## Folder Deletion Summary

You have successfully learned how to delete folders and their contents in the Circularo system.

### Key Concepts

* **Folder Deletion**: Removes both the folder structure and all documents it contains
* **Recursive Deletion**: Automatically removes all nested folders and their contents
* **Permission Requirements**: User must have edit rights to the folder and all its contents

### Best Practices

* Always verify the folder contents before deletion to avoid unintended data loss
* Consider exporting important folder contents before deletion for backup purposes
* Implement proper confirmation steps in your user interface before triggering folder deletion

### Example Implementation

> [!NOTE]
>
> See our OpenAPI documentation to learn about the full set of API endpoints and parameters.

> [!NOTE]
>
> Please use proper exception handling and function decomposition in your own code. The code is provided for illustrative purposes only and is not intended for production use.

```javascript theme={null}
// Folder deletion example
const URL = "https://sandbox.circularo.com";
const API_PATH = "/api/v1";
const TOKEN = "YOUR_AUTH_TOKEN"; // Obtained from login or API key
const FOLDER_ID = "YOUR_FOLDER_ID"; // ID of the folder you want to delete

try {
    // Delete the folder and all its contents
    const deleteResponse = await fetch(`${URL}${API_PATH}/documents?token=${TOKEN}&hardDelete=true`, {
        method: 'DELETE',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
            documents: [
                { id: FOLDER_ID }
            ]
        })
    });
    if (!deleteResponse.ok) {
        throw new Error(`Folder deletion failed: ${deleteResponse.status} ${deleteResponse.statusText}`);
    }

    const deleteResult = await deleteResponse.json();

    if (deleteResult.errors === false) {
        console.log(`Successfully deleted folder and ${deleteResult.count} item(s)`);
    } else {
        console.error('Some items could not be deleted:', deleteResult.items);
    }

} catch (error) {
    console.error('Error deleting folder:', error.message);
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.