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

# Delete File

> Delete a file from your Hubsy Cloud account

## Overview

Permanently delete a file from your Hubsy Cloud storage. This action cannot be undone.

## Path Parameters

<ParamField path="file_id" type="string" required>
  The unique identifier of the file to delete
</ParamField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X DELETE https://api.hubsy.cloud/v1/files/file_abc123 \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.hubsy.cloud/v1/files/file_abc123', {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  });

  const data = await response.json();
  console.log(data.success); // true
  ```

  ```python Python theme={null}
  import requests

  response = requests.delete(
      'https://api.hubsy.cloud/v1/files/file_abc123',
      headers={'Authorization': 'Bearer YOUR_API_KEY'}
  )

  result = response.json()
  ```

  ```php PHP theme={null}
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://api.hubsy.cloud/v1/files/file_abc123');
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      'Authorization: Bearer YOUR_API_KEY'
  ]);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  $data = json_decode($response, true);
  ```
</CodeGroup>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the deletion was successful
</ResponseField>

<ResponseField name="data" type="object">
  Information about the deleted file

  <Expandable title="Response Data">
    <ResponseField name="id" type="string">
      ID of the deleted file
    </ResponseField>

    <ResponseField name="name" type="string">
      Name of the deleted file
    </ResponseField>

    <ResponseField name="deleted_at" type="string">
      ISO 8601 timestamp of deletion
    </ResponseField>

    <ResponseField name="recoverable_until" type="string">
      ISO 8601 timestamp until file can be recovered from trash (30 days)
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Response

```json theme={null}
{
  "success": true,
  "data": {
    "id": "file_abc123",
    "name": "document.pdf",
    "deleted_at": "2024-01-15T16:45:00Z",
    "recoverable_until": "2024-02-14T16:45:00Z"
  }
}
```

## Error Responses

<ResponseExample>
  ```json File Not Found theme={null}
  {
    "success": false,
    "error": {
      "code": "not_found",
      "message": "File not found or already deleted"
    }
  }
  ```

  ```json Permission Denied theme={null}
  {
    "success": false,
    "error": {
      "code": "permission_denied",
      "message": "You don't have permission to delete this file"
    }
  }
  ```

  ```json Authentication Failed theme={null}
  {
    "success": false,
    "error": {
      "code": "authentication_failed",
      "message": "Invalid API key"
    }
  }
  ```
</ResponseExample>

## Important Notes

<AccordionGroup>
  <Accordion title="Trash and Recovery" icon="trash-arrow-up">
    Deleted files are moved to trash for 30 days:

    * Files remain recoverable for 30 days
    * After 30 days, files are permanently deleted
    * Use the restore endpoint to recover files
    * Storage space is freed only after permanent deletion
  </Accordion>

  <Accordion title="Shared Links" icon="link-slash">
    When a file is deleted:

    * All share links are immediately invalidated
    * Users with existing links can no longer access the file
    * Share analytics are preserved
    * Restoring the file does NOT restore share links
  </Accordion>

  <Accordion title="Permanent Deletion" icon="circle-exclamation">
    To permanently delete immediately:

    * Use the `permanent=true` query parameter
    * This bypasses the trash
    * Action cannot be undone
    * Requires elevated API key permissions
  </Accordion>
</AccordionGroup>

## Permanent Deletion

To permanently delete a file immediately (bypass trash):

```bash theme={null}
curl -X DELETE "https://api.hubsy.cloud/v1/files/file_abc123?permanent=true" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

<Warning>
  Permanent deletion cannot be undone. Files are immediately and irreversibly removed.
</Warning>

## Bulk Delete

Delete multiple files at once:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.hubsy.cloud/v1/files/bulk-delete \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "file_ids": ["file_abc123", "file_def456", "file_ghi789"]
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.hubsy.cloud/v1/files/bulk-delete', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      file_ids: ['file_abc123', 'file_def456', 'file_ghi789']
    })
  });
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.hubsy.cloud/v1/files/bulk-delete',
      json={'file_ids': ['file_abc123', 'file_def456', 'file_ghi789']},
      headers={'Authorization': 'Bearer YOUR_API_KEY'}
  )
  ```
</CodeGroup>

### Bulk Delete Response

```json theme={null}
{
  "success": true,
  "data": {
    "deleted": ["file_abc123", "file_def456", "file_ghi789"],
    "failed": [],
    "total": 3,
    "deleted_count": 3,
    "failed_count": 0
  }
}
```

## Restore Deleted File

Restore a file from trash:

```bash theme={null}
curl -X POST https://api.hubsy.cloud/v1/files/file_abc123/restore \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Restore Response

```json theme={null}
{
  "success": true,
  "data": {
    "id": "file_abc123",
    "name": "document.pdf",
    "restored_at": "2024-01-16T10:00:00Z",
    "folder_id": "folder_123"
  }
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="List Trash" icon="trash">
    `GET /trash` - View deleted files
  </Card>

  <Card title="Empty Trash" icon="trash-can">
    `DELETE /trash` - Permanently delete all trashed files
  </Card>

  <Card title="Restore File" icon="trash-arrow-up">
    `POST /files/{file_id}/restore` - Restore from trash
  </Card>

  <Card title="Bulk Delete" icon="layer-group">
    `POST /files/bulk-delete` - Delete multiple files
  </Card>
</CardGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Confirm Before Deleting" icon="circle-check">
    Always confirm with users:

    * Show file name and details
    * Explain trash/recovery period
    * Provide undo option
    * Log deletion for audit trail
  </Accordion>

  <Accordion title="Error Handling" icon="triangle-exclamation">
    Handle common scenarios:

    * File already deleted
    * Permission errors
    * Invalid file ID
    * Network timeouts
  </Accordion>

  <Accordion title="Bulk Operations" icon="layer-group">
    For multiple file deletions:

    * Use bulk delete endpoint
    * Handle partial failures
    * Show progress to users
    * Provide summary of results
  </Accordion>
</AccordionGroup>
