Delete File
Permanently delete a file from a project. This action cannot be undone.
Warning: File deletion is permanent and cannot be undone. Ensure you have backups before deleting files.
Endpoint
DELETE /api/projects/{project_id}/files/{filename}Authentication
Required: API key in Authorization header
Authorization: Bearer YOUR_API_KEYRequest
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
project_id | UUID | Yes | The project ID |
filename | string | Yes | The exact filename (case-sensitive) |
Response
Success Response (204 No Content)
No response body. HTTP status 204 indicates successful deletion.
Error Responses
| Status | Error | Description |
|---|---|---|
| 401 | Unauthorized | Invalid authentication |
| 404 | Not Found | File does not exist |
| 429 | Too Many Requests | Rate limit exceeded |
Examples
cURL
curl -X DELETE "https://markdownapi.io/api/projects/PROJECT_ID/files/article.mdx" \
-H "Authorization: Bearer YOUR_TOKEN"Python (httpx)
async def delete_file(project_id: str, filename: str):
api_key = os.getenv("MARKDOWN_API_KEY")
async with httpx.AsyncClient() as client:
response = await client.delete(
f"https://markdownapi.io/api/projects/{project_id}/files/{filename}",
headers={"Authorization": f"Bearer {api_key}"},
timeout=30.0
)
response.raise_for_status()
print(f"✓ File deleted: {filename}")
return TrueTypeScript
async function deleteFile(projectId: string, filename: string): Promise<boolean> {
const response = await fetch(
`https://markdownapi.io/api/projects/${projectId}/files/${filename}`,
{
method: 'DELETE',
headers: { 'Authorization': `Bearer ${process.env.MARKDOWN_API_KEY!}` },
}
);
if (!response.ok) {
if (response.status === 404) {
console.error(`File '${filename}' not found`);
return false;
}
throw new Error(`HTTP ${response.status}`);
}
console.log('✓ File deleted successfully');
return true;
}Best Practices
- Always confirm before deletion
- Create backups before deleting
- Log deletions for audit trail
- Handle 404 gracefully (file already deleted)
- Consider soft delete for critical files
Example: Delete with Backup
async def delete_with_backup(project_id: str, filename: str, backup_dir: str = "./backups"):
import os
from datetime import datetime
# Create backup
os.makedirs(backup_dir, exist_ok=True)
content = await download_file(project_id, filename)
timestamp = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
backup_path = os.path.join(backup_dir, f"{filename}.{timestamp}.backup")
with open(backup_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Backup created: {backup_path}")
# Delete file
await delete_file(project_id, filename)
print(f"✓ File deleted (backup: {backup_path})")What Gets Deleted
- ✅ File content from GCS
- ✅ Database record
- ✅ File metadata
- ❌ Project (not affected)
- ❌ Other files (not affected)
Project Updates
After deletion:
- Project
file_countdecremented - Project
total_size_bytesreduced - Project
updated_dateupdated
See Also
- Upload File - Add files to project
- List Files - View files in project
- Download File - Backup before deleting
- Delete Project - Delete entire project
Last updated on