guideData deletion

# 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.

Please remember that this action is irreversible. All document data will be permanently deleted from the database.

# 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.

# Troubleshooting

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