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
    https://accounts.zoho.com/oauth/v2/token?code={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

  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

    • 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 with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use ...
    • 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 ...
    • Initialization - Python SDK

      Now the app is ready to be initialized after defining configuration file/dictionary for your app. Generating grant and refresh tokens For a Single User(self-authorized) For self client apps, the self authorized grant token should be generated from ...
    • Register your application - Node JS SDK

      All the Zoho CRM APIs are authenticated with OAuth2 standards, so it is mandatory to register and authenticate your client app with Zoho. To register: Go to the site: accounts.zoho.com/developerconsole Click Add Client ID.  Enter the Client ...
    • Initialization - C# SDK

      Now the app is ready to be initialized after defining configuration file/dictionary for your app. Generating Grant tokens For a Single User(self-authorized) For self client apps, the self authorized grant token should be generated from the Zoho ...