Node JS

Node JS SDK for Zoho CRM

Node SDK is a wrapper for Zoho CRM APIs. Hence invoking a Zoho CRM API from your Node application is just a function call which provide the most appropriate response.

This SDK supports both single user as well as multi user authentication.

Registering a Zoho Client

Since Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:

  1. Visit this page
  2. Click on “Add Client ID”.
  3. Enter Client Name, Client Domain and Redirect URI.
  4. Select the Client Type as "Web based".
  5. Click “Create”.
  6. Your Client app would have been created and displayed by now.
  7. The newly registered app's Client ID and Client Secret can be found by clicking Options → Edit.
    (Options is the three dot icon at the right corner).

Installation of Node CRM SDK

Node JS SDK will be installed and a package named 'zcrmsdk' will be created in the local machine.

The package can be added using the following code:

var ZCRMRestClient = require('zcrmsdk')

Installing the SDK

Here's how you install the Node JS SDK

  • Run the command below:

    npm install zcrmsdk

Another method to install the SDK is to add it in dependencies to the package.json of the node server with the latest version (recommended) and to run npm install in the directory which installs all the dependencies mentioned in package.json.

Upgrade the SDK

  • Run this command to upgrade the Node JS SDK to the latest version.

    npm install --upgrade zcrmsdk


Your OAuth Client details should be given to the SDK as a property file. In the SDK, you need to configure a file named Please place the respective values in that file. You can place it under resources folder from where the SDK is used.

Please fill the values for the following keys alone.

Based on your domain(EU,CN), please change the value of crm.iamurl. Default value set as US domain.

In file:


  • crm.clientid, crm.clientsecret and crm.redirecturl are your OAuth client’s configurations that you get after registering your Zoho client.
  • crm.iamurl is the accounts URL. It may be or If the crm.iamurl is not specified, by default the URL will be

In file:


  • api.url is the URL used to call APIs. By default, the URL is
  • api.user_identifier will be empty by default. For single user authentication, this key can be filled with the respective email id, so that all calls happens by using this user's authentication.
  • api.tokenmanagement is given as a measure to manage and maintain tokens. If tokenmanagement is not provided, then sdk's default implementation(mysql) will be followed.

The above keys specified in file are all optional.

Token Storage Mechanism

To use the default token storage provided by the SDK, the following are to be done:

Mysql should be running in default port in localhost.

Database with name zohooauth should be created and a table with below configurations should be present in the database. Table, named "oauthtokens", should have the columns "useridentifier" (varchar) "accesstoken" (varchar), "refreshtoken" (varchar) and "expirytime" (bigint).

Once the configuration is set, storage and retrieval of tokens will be handled by the SDK.

If the user wants to utilize their own mechanism, they can mention it in by providing the respective module in api.tokenmanagement.

This module should contain the below methods,

  1. saveOAuthTokens(token_obj)
  2. updateOAuthTokens(token_obj)
    • Irrespective of response, the next execution happens. So care should be taken by the user in handling their module.
  3. getOAuthTokens()
    • The expected response for this method : JSON response containing expirytime, refreshtoken and accesstoken fields.

saveoauthtoken & updateOAuthTokens will be called with JSON parameters, which contain fields given below,



Whenever the app is started, the below code snippet is to be called for initialization.

var ZCRMRestClient = require('zcrmsdk');
//do whatever required after initialize

Generating self-authorized grant and refresh token

For self client apps, the self authorized grant token should be generated from the Zoho Developer Console (

  1. Visit
  2. Click OptionsSelf Client of the client for which you wish to authorize.
  3. Enter one or more (comma separated) valid Zoho CRM scopes that you wish to authorize in the “Scope” field and choose the time of expiry. Provide “aaaserver.profile.READ” scope along with Zoho CRM scopes.
  4. Copy the grant token for backup.
  5. Generate refresh_token from grant token by making a POST request with the URL below{grant_token}&redirect_uri={redirect_uri}&client_id={client_id}&client_secret={client_secret}&grant_type=authorization_code

  6. Copy the refresh token for backup.

Please note that the generated grant token is valid only for the stipulated time you chose while generating it. Hence, the access and refresh tokens should be generated within that time.

Each time server is restarted, this function has to be called and both the configuration files should be populated with proper values before calling this function, else exception will be thrown.

All functions return promises in zcrm node sdk.

Getting access and refresh tokens from grant token through method calls

console.log("access token :"+auth_response.access_token);
console.log("refresh token :"+auth_response.refresh_token);
console.log("expires in :"+auth_response.expires_in);

The access and refresh tokens are generated. In case the access token is expired, the SDK will refresh it automatically.

If the user has refresh token and need to generate access token below function can be used,

console.log("access token :"+auth_response.access_token);
console.log("refresh token :"+auth_response.refresh_token);
console.log("expires in :"+auth_response.expires_in);

Sample API call for getting Modules:

var input ={};
input.module = "Leads";
var params = {}; = 0;
params.per_page = 5;
input.params = params;
    var result = "<html><body><b> Top 5 Leads</b>";
    var data = response.body;
    data = JSON.parse(data);
    data =;
    for (i in data){
        var record = data[i];
        var name = record.Full_Name;




As appearing in the hierarchy, zcrmsdk entity module has variables to fetch its own and other modules properties.

For example, to call an API to get module data, the request should be zcrmsdk.API.MODULES.{operation_type}. The operation types can be GET, POST, PUT, DELETE or CREATE.

Response Handling

All API calls will give the actual API response given by Zoho APIs, except file download.

For file download, the response will contain an extra field filename.

Error Handling:

All errors will be thrown explicitly and care should be taken in catching the same.

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: