Skip to Content

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_KEY

Request

Path Parameters

ParameterTypeRequiredDescription
project_idUUIDYesThe project ID
filenamestringYesThe exact filename (case-sensitive)

Response

Success Response (204 No Content)

No response body. HTTP status 204 indicates successful deletion.

Error Responses

StatusErrorDescription
401UnauthorizedInvalid authentication
404Not FoundFile does not exist
429Too Many RequestsRate 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 True

TypeScript

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

  1. Always confirm before deletion
  2. Create backups before deleting
  3. Log deletions for audit trail
  4. Handle 404 gracefully (file already deleted)
  5. 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_count decremented
  • Project total_size_bytes reduced
  • Project updated_date updated

See Also

Last updated on