Skip to main content
Permanently deletes a file from storage using its unique ID. This action cannot be undone, so use with caution.
DELETE https://api.worqhat.com/storage/delete/{fileId}

What Does This Endpoint Do?

This endpoint allows you to permanently remove a file from WorqHat storage. Think of it like deleting a file from your computer’s trash - once deleted, the file cannot be recovered.

When to Use Delete File

You’ll find this endpoint useful when you need to:
  • Clean up old files: Remove outdated or unnecessary files
  • Implement data retention policies: Delete files that are beyond your retention period
  • Free up storage space: Remove large files to make room for new ones
  • Handle user requests: Delete user data upon request (e.g., for privacy compliance)
  • Remove temporary files: Clean up files that were only needed temporarily
  • Manage storage costs: Delete files to reduce storage usage and costs

How It Works

  1. You provide the file ID (obtained when you uploaded the file)
  2. The API locates the file in your organization’s storage
  3. The API permanently deletes the file from storage
  4. The API returns confirmation of the deletion

Code Examples

Example 1: Basic File Deletion

This example shows how to delete a file using its ID.
  • Node.js
  • Python
  • Go
  • cURL
import Worqhat from 'worqhat';

// Initialize the client with your API key
const client = new Worqhat({
  apiKey: process.env.WORQHAT_API_KEY, // Always use environment variables for API keys
});

async function deleteDocument() {
  try {
    const fileId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
    
    // Call the deleteFileByID method
    const response = await client.storage.deleteFileByID(fileId);
    
    // Handle the successful response
    console.log('File deleted successfully!');
    console.log('Message:', response.message);
    console.log('Deleted at:', response.deletedAt);
    return response;
  } catch (error) {
    // Handle any errors
    console.error('Error deleting file:', error.message);
  }
}

// Call the function
deleteDocument();

Example 2: Batch File Deletion

This example shows how to delete multiple files in sequence.
  • Node.js
  • Python
  • Go
  • cURL
import Worqhat from 'worqhat';

// Initialize the client with your API key
const client = new Worqhat({
  apiKey: process.env.WORQHAT_API_KEY,
});

async function deleteMultipleFiles() {
  try {
    const fileIds = [
      'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
      'b2c3d4e5-f6g7-8901-bcde-f23456789012',
      'c3d4e5f6-g7h8-9012-cdef-345678901234'
    ];
    
    const results = [];
    
    for (const fileId of fileIds) {
      try {
        const response = await client.storage.deleteFileByID(fileId);
        results.push({ fileId, success: true, message: response.message });
        console.log(`Deleted file ${fileId}: ${response.message}`);
      } catch (error) {
        results.push({ fileId, success: false, error: error.message });
        console.error(`Failed to delete file ${fileId}:`, error.message);
      }
    }
    
    console.log('Batch deletion completed:', results);
    return results;
  } catch (error) {
    console.error('Error in batch deletion:', error.message);
  }
}

deleteMultipleFiles();

Request Parameters

fileId
string
required
The unique identifier of the file to delete. This is the ID that was returned when you uploaded the file.Example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"

Response Fields Explained

success
boolean
true if the file was deleted successfully, false otherwise.
message
string
A human-readable message describing the result of the deletion operation.
deletedAt
string
The timestamp when the file was deleted (ISO 8601 format).

Example Response

{
  "success": true,
  "message": "File deleted successfully",
  "deletedAt": "2025-07-26T03:28:08.123Z"
}

Common Errors and How to Fix Them

ErrorCauseSolution
”File not found”The file ID doesn’t exist or has already been deletedCheck that the file ID is correct and the file still exists
”Invalid file ID”The file ID format is incorrectUse a valid UUID format for the file ID
”Unauthorized”Invalid or missing API keyCheck that you’re using a valid API key
”File access denied”You don’t have permission to delete this fileEnsure the file belongs to your organization

Tips for Safe File Deletion

  • Double-check file IDs before deleting to avoid accidental deletions
  • Implement confirmation steps in user interfaces before deletion
  • Keep backups of important files before deletion
  • Use batch deletion carefully to avoid deleting too many files at once
  • Log deletion activities for audit purposes
  • Consider soft deletion for files that might need to be recovered
  • Test deletion in development before using in production
I