How to Delete Comparisons in Draftable API
When using the Draftable API, comparisons and their associated documents are stored on the server until they are deleted. Over time, this can result in significant storage usage, particularly in self-hosted deployments where documents accumulate in the /var directory.
This guide explains the three approaches to managing comparison lifecycle and deletion:
- Manual Deletion - Explicitly delete comparisons via API calls
- Comparison Expiry - Automatically delete comparisons after a specified time
- URL Expiry - Control viewer URL validity (does not delete documents)
URL Expiry vs Comparison Expiry: A common misconception is that setting a URL expiry will delete the comparison and its documents. This is not the case. URL expiry only controls how long the viewer link remains valid—the comparison and documents remain on disk until explicitly deleted or until the comparison expires.
Method 1: Manual Deletion
You can permanently delete a comparison at any time using the delete method. This immediately removes the comparison and all associated documents from storage.
After deletion, the comparison identifier becomes available for reuse. Note: In the Node.js client, the delete method is called destroy().
Bulk Deletion Example
To delete multiple or all comparisons (e.g., for cleanup), you can retrieve and iterate through your comparisons:
Method 2: Comparison Expiry (Automatic Deletion)
The recommended approach for managing storage is to set an expiry time when creating comparisons. When a comparison expires, the system automatically deletes the comparison and all associated documents from storage.
When Does a Comparison Become “Expired”?
A comparison receives the “expired” status when the current time passes the expiry_time that was set during creation. Once expired:
- The comparison becomes inaccessible via the API
- The system automatically deletes the comparison data
- All associated documents are removed from storage (e.g., the
/var directory in self-hosted deployments)
Best Practice: Always set an appropriate expires value when creating comparisons. This ensures automatic cleanup and prevents storage from growing indefinitely. Common expiry periods include:
- 30 minutes to 2 hours for temporary/preview comparisons
- 24 hours to 7 days for standard document reviews
- 30 days for long-term reference comparisons
Method 3: URL Expiry (Does NOT Delete Documents)
When generating signed viewer URLs for private comparisons, you can set how long the URL remains valid. This is not the same as comparison expiry.
Important: URL expiry only controls the validity of the viewer link. When a URL expires:
- Users see an “expired link” error message
- The comparison and documents remain on disk
- Storage is not freed
To delete documents and free storage, you must use comparison expiry or manual deletion.
After the URL expires, users cannot access the viewer via that link, but the comparison still exists and can be accessed with a new signed URL.
Comparison: Expiry Methods
Recommended Approach
For most use cases, we recommend combining comparison expiry with URL expiry:
This approach ensures:
- Documents are automatically cleaned up after a reasonable period
- URLs can be regenerated as needed while the comparison exists
- Storage usage remains under control
Need Help?
If you have questions about managing comparisons or storage in your Draftable deployment, please contact us at support@draftable.com.