Sign up (with export icon)

Data deletion

Show the table of contents

Overview

There are a few ways to different delete data from the server:

Document delete

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.

Example

The example below has been prepared in Node.js.

  1. Run the following commands
mkdir cs-document-delete-example && cd cs-document-delete-example && npm init -y && npm i axios && touch delete.cjs
  1. Open cs-document-delete-example/delete.cjs and 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' );
}
  1. Update your credentials, and the documentId value in the code snippet with the id of an existing document.

  2. Execute the node delete.cjs command.

After a successful response with a status code 204 from the delete request, the document with all resources will be deleted from the server.

Document observability hub data

The Document observability hub keeps its own record of each document. This way, it can still show what happened to a document after the document was deleted.

  • Deleting the document content from storage with the Storage REST API adds the Removed from storage action to the document’s history. The document itself stays.
  • Deleting the whole document with the Documents REST API adds the Document removed action and marks the document as deleted. Its history, storage saves, and snapshot debug bundles stay available in the hub for 14 days. On-Premises uses 14 days by default and you can change it with the OBSERVABILITY_HUB_RETENTION_IN_DAYS environmental variable. During that time you can still download a snapshot to recover the content.
  • Removing the environment deletes all of its hub data right away, without waiting for the retention period.

The entry of a deleted document is not subject to retention – it stays in the hub until the environment is removed. If a new document is later created with the same ID, the hub treats it as a new document and clears the deleted mark. The older history of that ID is still shown until it expires.

Troubleshooting

  • We suggest enabling Insight Panel, where you will find detailed logs from the whole process including exact reasons for any failed requests.