How to generate a hash for the API

The instructions below are for desktops and laptops only.

Using a hash with your API calls helps secure your customers’ data. A hash encrypts your secret key and user ID into a string that unauthorized users cannot read. This guide explains how to retrieve your secret key and generate a hash for use with functions like login() and setAttributes().

Get your secret key

1. Log in to your tawk.to account.


2. Select the correct property.

3. Click Administration in the top menu.

4. Click Overview in the left menu.

5. Scroll to JavaScript API. Then, enable Secure Mode.

6. Click the copy icon next to the key to save it for later.

Generate the hash

You can use any encryption library to create a hash. This example uses Crypto.js (also available via npm).

1. Copy the following code into the <head> section of your website’s HTML:

2. Include a JavaScript function that generates the hash value.

3. Replace secretKey in the function with the key you copied from your tawk.to dashboard.

Note: When using the hash with the login() function, customer conversations may take a few seconds to appear after login.

Common error codes

Error codeDescription
400 Bad Request ErrorThis indicates an error in your function’s attributes. Check your code and re-send the request.
401 Unauthorized ErrorThis indicates that
  • The user ID doesn’t match the encrypted hash value, or
  • Secure Mode isn’t enable in your tawk.to dashboard.

Verify the user ID and ensure Secure Mode is enabled in the dashboard
500 Internal Server ErrorThis indicates our servers are currently busy. Try re-sending the request.

These errors appear in your browser’s developer console.

Additional considerations

  • Always keep your secret key secure; do not share it publicly.

  • If using multiple properties, ensure you generate a hash for the correct property key.

  • The hash only encrypts API calls—it does not encrypt other dashboard or widget data.

Related guides


If you have feedback about this article, or if you need more help:

Was this article helpful?

5 out of 7 liked this article

Still need help? Message Us