Initialization - Node JS SDK

Initialization - Node JS SDK

Whenever the app is started, the below code snippet is to be called for initialization.
  1. var ZCRMRestClient = require('zcrmsdk');
  2. ZCRMRestClient.initialize().then(function()
  3. {
  4. //do whatever required after initialize
  5. })

Generating self-authorized grant and refresh token

For self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)
  1. Visit https://accounts.zoho.com/developerconsole
  2. Click Options → Self 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
  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

  1. ZCRMRestClient.generateAuthTokens(user_identifier,grant_token).then(function(auth_response){
  2. console.log("access token :"+auth_response.access_token);
  3. console.log("refresh token :"+auth_response.refresh_token);
  4. console.log("expires in :"+auth_response.expires_in);
  5. });
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,
  1. ZCRMRestClient.generateAuthTokenfromRefreshToken(user_identifier,refresh_token).then(function(auth_response){
  2. console.log("access token :"+auth_response.access_token);
  3. console.log("refresh token :"+auth_response.refresh_token);
  4. console.log("expires in :"+auth_response.expires_in);
  5. });

Sample API call for getting Leads:

  1. var input ={};
  2. input.module = "Leads";
  3. var params = {};
  4. params.page = 0;
  5. params.per_page = 5;
  6. input.params = params;
  7. zcrmsdk.API.MODULES.get(input).then(function(response){
  8.     var result = "<html><body><b>Leads</b>";
  9.     var data = response.body;
  10.     data = JSON.parse(data);
  11.     data = data.data;
  12.     for (i in data){
  13.         var record = data[i];
  14.         var name = record.Full_Name;
  15.         result+="<span>"+name+"</span>";
  16.     }
  17.     result+="</body></html>";
  18.    })




    • Related Articles

    • Installation - Node JS 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 Run the command below to install the Node ...
    • Configuration - Node JS SDK

      Your OAuth Client details should be given to the SDK as a property file. In the SDK, you need to configure a file named oauth_configuration.properties. Please place the respective values in that file. You can place it under resources folder from ...
    • Node JS SDK - An Overview

      Node JS SDK offers a way to create client node js applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs easy. In other words, it serves as a wrapper for the REST APIs, making it easier to use the ...
    • Release Notes - Node JS SDK

      ZCRMSDK -VERSION 0.0.15 Install command npm install zcrmsdk@0.0.15 Notes Enhancement: User identifier default value handled in get method. ZCRMSDK -VERSION 0.0.14 Install command npm install zcrmsdk@0.0.14 Notes Issue fix: Default user identifier set ...
    • Class Hierarchy - Node JS SDK

      All Zoho CRM entities are modelled as modules having classes, methods and instance variables applicable to that particular entity. ZCRMRestClient is the base class of the Python SDK. ZCRMRestClient has methods to get instances of various other Zoho ...