Data deletion
There are a few ways to different delete data from the server:
- Collaboration REST API to delete only active collaboration session data.
- Storage REST API to delete document content from the document storage.
- Suggestions REST API to delete comments.
- Comments REST API to delete suggestions.
As you can see, all the above request deletes only part of the entire document. Depending on your needs, you may want to delete the entire document with all comments, suggestions, and more. To do this you can use Documents REST API.
Please remember that this action is irreversible. All document data will be permanently deleted from the database.
The example below has been prepared in Node.js.
- Run the following commands
mkdir cs-document-delete-example && cd cs-document-delete-example && npm init -y && npm i axios && touch delete.cjs
Copy code
- Open
cs-document-delete-example/delete.cjsand paste the following code snippet:
const crypto = require( 'crypto' );
const axios = require( 'axios' );
// Update with your credentials and application endpoint
const environmentId = 'txQ9sTfqmXUyWU5LmDbr';
const apiSecret = '4zZBCQoPfRZ7Rr7TEnGAuRsGgbfF58Eg0PA8xcLD2kvPhjGjy4VGgB8k0hXn';
const applicationEndpoint = 'https://33333.cke-cs.com';
// Set document id
const documentId = 'my_document_id';
const deleteApiEndpoint = `${ applicationEndpoint }/api/v5/${ environmentId }/documents/${ documentId }`;
( async () => {
await deleteDocument();
async function deleteDocument( ) {
try {
const config = getConfig( 'DELETE', deleteApiEndpoint );
const response = await axios.delete( deleteApiEndpoint, config );
console.log( response.status );
} catch ( error ) {
console.log( error.message );
console.log( error.response.data );
}
}
} )();
function getConfig( method, url ) {
const CSTimestamp = Date.now();
return {
headers: {
'X-CS-Timestamp': CSTimestamp,
'X-CS-Signature': generateSignature( apiSecret, method, url, CSTimestamp )
}
};
}
function generateSignature( secret, method, uri, timestamp, body ) {
const url = new URL( uri );
const path = url.pathname + url.search;
const hmac = crypto.createHmac( 'SHA256', secret );
hmac.update( `${ method.toUpperCase() }${ path }${ timestamp }` );
if ( body ) {
hmac.update( Buffer.from( JSON.stringify( body ) ) );
}
return hmac.digest( 'hex' );
}
Copy code
-
Update your credentials, and the
documentIdvalue in the code snippet with the id of an existing document. -
Execute the
node delete.cjscommand.
After a successful response with a status code 204 from the delete request, the document with all resources will be deleted from the server.
- We suggest enabling Insight Panel, where you will find detailed logs from the whole process including exact reasons for any failed requests.