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 where the SDK is used.
Property File
Based on your domain(EU,CN), please change the value of "crm.iamurl". Default value set as US domain.
In oauth_configuration.properties file:
- [zoho]
- crm.iamurl=
- crm.clientid=
- crm.clientsecret=
- crm.redirecturl=
- 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 accounts.zoho.com or accounts.zoho.eu. If the crm.iamurl is not specified, by default the URL will be accounts.zoho.com.
Please fill the values for the following keys alone.
In configuration.properties file:
- [crm]
- api.url=
- api.user_identifier=
- api.tokenmanagement=
- [mysql]
- username=
- password=
- api.url is the URL used to call APIs. By default, the URL is www.zohoapis.com.
- 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.
- username and password can be given here if you already have one created for your MySQL.
The above keys specified in configuration.properties 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 configuration.properties by providing the respective module in api.tokenmanagement.
This module should contain the below methods,
- saveOAuthTokens(token_obj)
- updateOAuthTokens(token_obj)
- Irrespective of response, the next execution happens. So care should be taken by the user in handling their module.
- getOAuthTokens()
- The expected response for this method : JSON array containing json response with expirytime, refreshtoken and accesstoken fields.
Note
All methods should return promise.
saveOAuthtoken & updateOAuthTokens will be called with JSON parameters, which contain fields given below,
- access_token
- refresh_token
- expires_in
Sample code for custom token management getOAuthTokens()
- tokenmanagement.getOAuthTokens = function(user_identifier){ //expires in : 1527839622728
- return new Promise(function(resolve,reject){
- var result = {};
- result.accesstoken = '1000.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx';
- result.expirytime = 15278396227289
- result.refreshtoken = '1000.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx';
- var result_array =[];
- result_array.push(result);
- resolve(result_array);
- });
- }
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 ...
Initialization - Node JS SDK
Whenever the app is started, the below code snippet is to be called for initialization. var ZCRMRestClient = require('zcrmsdk'); ZCRMRestClient.initialize().then(function() { //do whatever required after initialize }) Generating self-authorized grant ...
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 ...
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 ...
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 ...