Kaizen #20 - Node JS SDK

Kaizen #20 - Node JS SDK

Hello everyone!
Welcome to another week of Kaizen!
In today's post, we will discuss the Node JS SDK.

What is the Node JS SDK for Zoho CRM?
Node JS SDK allows you to create client Node JS applications that you can integrate with Zoho CRM, effortlessly. It serves as a wrapper for the REST APIs, thus making it easier to use the services of Zoho CRM.

What can you do with the Node JS SDK?
  • Exchange data between Zoho CRM and the client application where the CRM entities are modelled as functions.
  • Authenticate your application easily every time you sync data between Zoho CRM and your application, as the SDK takes care of generating the access/refresh tokens automatically.
How to start using the Node JS SDK?
Follow the below steps:
  • Step-1: Register your application (Self Client or Web-based client)
  • Step-2: Install the SDK
  • Step-3: Import the SDK in your project
  • Step-4: Initialize the SDK
    4.a. Choose the token persistence method
    4.b. Setup the configuration files or dictionary
    4.c. Generate the tokens
  • Step-5: Connect to Zoho CRM through the available functions

Let us now discuss these steps in detail.

Step-1: Register your application
All the Zoho CRM APIs are authenticated by the OAuth2.0 standards. It is mandatory to authenticate your application with Zoho.
You can register your application either as a Self Client (single user app) or a web-based app (multiple users app).

1.a. Self Client
  • Go to https://api-console.zoho.com.
  • Click ADD CLIENT
  • Choose the Client Type as Self Client, and click CREATE.
  • You will receive a client ID and a client secret upon successful registration.


1.b. Web-based Client
  • Go to https://api-console.zoho.com.
  • Click ADD CLIENT
  • Choose the client as Web based and click CREATE NOW.
  • Specify the client name, homepage URL of your application's UI, and a redirect URI to which you want to redirect the users after they grant consent to your application.
  • Click CREATE. Your Client ID and Client Secret will be displayed.


Step-2: Install the SDK
You can install the Node JS SDK through npm package manager. Run the below command.

npm install zcrmsdk

Run the below command to update your SDK to the latest version.

npm install --upgrade zcrmsdk
After the installation, a package named 'zcrmsdk' will be created in the node modules folder in your machine.

Step-3: Import the SDK in your project
Use the below statement in your code to import the downloaded SDK.

var ZCRMRestClient = require('zcrmsdk')

Step-4: Initialize the SDK 
Initializing the SDK involves the following steps.
  • Step 4.a - Choosing the token persistence method
  • Step 4.b - Setting up the oauth and configuration properties files
  • Step 4.c - Generating the tokens

4.a. Token Persistence
Your application should retain tokens (grant, access, and refresh tokens) to automate the process of data sync between your Node JS application and Zoho CRM.

You can choose to persist (store) the tokens in two ways.
      a. MySQL Persistence (default)
      b. Custom DB Persistence

a. MySQL Persistence
When you want to store the tokens in the MySQL DB, include the following keys in the configuration.properties file (discussed in the next section) or the configuration JSON array, along with other mandatory keys.

username=mysql_username
password=mysql_password

Note
When you use MySQL persistence, ensure that
  • MySQL runs in the same machine serving at the mentioned port (by default 3306).
  • There is a database named zohooauth.
  • There is a table name oauthtokens with the columns useridentifier (varchar(100)), accesstoken (varchar(100)), refreshtoken (varchar(100)) and expirytime (bigint).
b. Custom DB Persistence
To use custom DB persistence, you must write a custom implementation of the following functions:
  • getOAuthTokens() - This method returns the user identifier, access and refresh tokens, and their respective expiry time.
  • saveOAuthTokens(token_obj) - This method saves the access and refresh tokens, their respective expiry time. This method is called when you generate the access token through the grant token or the refresh token.
  • updateOAuthTokens(token_obj) - This method updates the access token and the expiry time every time an access token is refreshed. This method is called when the access token expires.

Include the absolute path of the file that contains the above methods in the following key of the configuration.properties file.

api.tokenmanagement=absolute_path_to _the_custom_implementation

The below images contain a sample of the custom implementation of the above three methods. You can find the code for the same as an attachment to this post.
This implementation of custom persistence creates a token file named zcrm_oauthtokens.txt and this file will contain the below keys with their values.

{"tokens": [{"access_token":"1000.xxxxx","expires_in":1582804396157,"user_identifier":"Patricia.boyle@abc.com","refresh_token":"xxx"}]}
getOAuthTokens()


updateOAuthTokens()


saveOAuthTokens()


Note
  • While updating the tokens, the next execution happens irrespective of the response. So, you must exercise care to handle this in your module.
  • All methods must return a Promise.
4.b. Configuration
You can set the configuration details in property files (oauth_configuration.properties and configuration.properties) or pass the details during run time as JSON key-value pairs.

oauth_configuration.properties
This file must contain the below client details.

[zoho]
crm.iamurl=accounts.zoho.com
crm.clientid=1000.xxxxxxx.6WJ
crm.clientsecret=99xxxxx0e16
crm.redirecturl=https://www.zoho.com

Where,
  • crm.iamurl - The domain-specific accounts URL from which you generate the grant token (authorization code). Possible domains are accounts.zoho.com (US), accounts.zoho.eu (EU), accounts.zoho.in (India), accounts.zoho.com.cn(China), accounts.zoho.com.au (Australia). The default value is accounts.zoho.com.
  • crm.clientid, crm.clientsecret - The client ID and client secret, respectively, you received while registering your application.
  • crm.redirecturl - The redirect URI you specified while registering your client. For self client apps, you can specify a dummy value for this key.
configuration.properties

This file must contain the below details.

[crm]
api.url=www.zohoapis.com
api.user_identifier=p.boyle@abc.com
[customDB]//If you want to use custom DB persistence
api.tokenmanagement=
[mysql]//If you want to use MySQL DB persistence
username=*****
password=*****

Where,
  • api.url - The domain-specific URL from which your app must make API calls to Zoho CRM. Possible URLs are www.zohoapis.com (US), www.zohoapis.eu (EU), www.zohoapis.in (India), www.zohoapis.com.cn(China), www.zohoapis.com.au (Australia). The default value is www.zohoapis.com.
  • api.user_identifier - The email ID of the current user.
  • api.tokenmanagement - The absolute or relative path to the file that contains the token storage mechanism. This key is mandatory for custom DB persistence.
  • username, password - The MySQL username and password, respectively. These keys are mandatory for MySQL DB persistence.
Note
Both these files must be placed under the resources folder of your project.

Config JSON Array
Instead of specifying the configuration details in properties files, you can choose to pass the details to the SDK during run time as JSON key-value pairs, as shown below.

var ZCRMRestClient = require('zcrmsdk');
var configJson={
        "client_id":"{client_id}",//mandatory
        "client_secret":"{client_secret}",//mandatory
        "redirect_uri":"{redirect_url}",//mandatory
        "user_identifier":"{user_identifier}",
        "mysql_username":"{mysql_username}",//optional ,"root" is default value
        "mysql_password":"{mysql_password}",//optional ,"" is default value
        "base_url":"{api_base_url}",//optional ,"www.zohoapis.com" is default value
        "iamurl":"{accounts_url}",//optional ,"accounts.zoho.com" is default value
        "version":"{api_version}",//optional ,"v2" is default value
        "tokenmanagement":"{token_management_module}"//optional ,mysql module is default
}
ZCRMRestClient.initialize(configJson).then(function()
{
//do whatever required after initialize
})

Now that you have created and registered your app with Zoho, you must authenticate it. 

4.c. Generating the tokens
As the V2 Zoho CRM APIs follow the OAuth2.0 protocol, it is mandatory to authorize the OAuth2.0 app before using the SDK functions with an access token.
You can generate an access token from a grant token.
You can generate the grant token in two ways based on the type of client.

For Self Client Applications
  • Log in to Zoho and go to Zoho Developer Console.
  • Select your Self Client.
  • Provide the necessary scopes separated by commas, along with the scope aaaserver.profile.READ
  • Select the Time Duration from the drop-down. This is the time the grant token is valid for.
  • Provide a description for the scopes. Click GENERATE.
  • Copy the grant token.
For Web-based Applications
It is the responsibility of your client app to generate the grant token for the users trying to login.
Your Application's UI must have the Login with Zoho option to open the grant token URL of Zoho, which would prompt for the user's OAuth2.0 authorization.
Upon the successful login of the user, the grant token will be sent as a parameter to your registered redirect URL.

Generating an access token from the grant token
Use the below code snippet in your main class.

ZCRMRestClient.generateAuthTokens(user_identifier,grant_token).then(function(auth_response){
console.log("access token :"+auth_response.access_token);
console.log("refresh token :"+auth_response.refresh_token);
console.log("expires in :"+auth_response.expires_in);
});

Note
  • The code snippet to generate the access token from the grant token is valid only once per grant token. If the grant token expires before you generate the access token, you must generate a new grant token only.
  • Generating access and refresh tokens is a one-time process. After the tokens are generated the first time, the SDK persists them based on the keys defined in the configuration dictionary or the properties file, and refreshes the access token as and when required.

Step-5: Connect to Zoho CRM through the available methods

Here is a sample to insert a lead. You can find the code for this sample in the attachment.



The isTokenGenerated Method

You need to add this method to check if the access token has already been generated or not. It returns a Boolean value.

true - The access token has already been generated. 
false - The access token has not been generated previously, thus, it shifts the control to the code snippet that leads to access token generation.

For more sample codes, refer to REST API samples.


We hope you found this post useful. Stay tuned for more!
Cheers!




    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Kaizen #198: Using Client Script for Custom Validation in Blueprint

                                                              Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

                                                              Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
                                                            • Kaizen #193: Creating different fields in Zoho CRM through API

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Client Script | Update - Introducing Commands in Client Script!

                                                              Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • 【Zoho Projects】サンドボックス機能(テスト環境)リリースのお知らせ

                                                                                                              本投稿は、本社のZoho コミュニティに投稿された以下の記事を参照し作成したものです。 Sandbox - Your Secure Testing Space in Zoho Projects ユーザーの皆さま、こんにちは。コミュニティチームの中野です。 本投稿では、Zoho Projects のサンドボックス機能リリースについてご紹介します。 サンドボックス(テスト環境)とは? Zoho Projects の「サンドボックス」は、新たな設定を作成、検証、そして既存の処理を妨げることなく本番環境に適用することができるテスト環境です。
                                                                                                            • Sending from domain alias

                                                                                                              In the Control Panel/Domains, I have set up some domains as aliases for my main domain. Only my main domain has mail hosting. The other domains are verified as aliases for the main domain, and emails sent to <user>@<alias domain> arrive successfully at
                                                                                                            • Difficult to Purchase More users

                                                                                                              It's surprisingly difficult and un-intuitive to purchase more user licenses in Zoho One under the new UI. It's not actually possible to do it anywhere from the admin interface. You have to leave the admin/directory section, then click your profile icon,
                                                                                                            • How to link web sales payments through Stripe to invoices?

                                                                                                              I have just set up an online shop website which accepts payments through Stripe.  The payment appears in Zoho Books through the Stripe feed as 'Sales without invoices'.  In order to keep Zoho Inventory in step, I manually (for now) create a Sales Invoice
                                                                                                            • Announcing New Features in Trident for macOS (v.1.22.0)

                                                                                                              Hello everyone! Trident for macOS (v.1.22.0) is here with thoughtful updates to improve your daily workflow. Here's a quick look at what's new. Switch email response type easily. You can now switch between Reply, Reply All, and Forward directly in the
                                                                                                            • Layout Rules / Quick create

                                                                                                              Hello, is there a way to create a layout rule for quick create option? Regards, Katarzyna
                                                                                                            • Zoho Notebook Will Not Open After App Install

                                                                                                              I am a new user of Notebook. I was able to successfully import my data from Evernote and the product is working well on a Windows 11 computer and Pixel device. I have also installed Notebook on a Samsung S6 lite tablet however the software freezes on
                                                                                                            • Project template after project creation

                                                                                                              How can I apply a project template AFTER the project has been created?
                                                                                                            • Leads, contacts, deals table view is not sorting

                                                                                                              i am unable to sort the table view of leads, contacts and deals
                                                                                                            • Conditional Layouts On Multi Select Field

                                                                                                              How we can use Conditional Layouts On Multi Select Field field? Please help.
                                                                                                            • Zoho CRM Multi-select values not translated

                                                                                                              Hello! I have some issue with translate custom multi-select fields in zoho CRM in other language. I download export file, but it has all my custom fields and picklist values exept multi-select fields picklist values.  Please, help me to undestand, is
                                                                                                            • Unable to Download Invoices via API – Code 57 Authorization Error

                                                                                                              I’m integrating the Zoho Billing API with the scopes ZohoInvoice.invoices.CREATE,ZohoInvoice.invoices.READ. I’ve completed the OAuth2 flow successfully, including generating the auth code, access token, and refresh token. All tokens are valid and fresh.
                                                                                                            • Weekly Tips : Stay in loop with Conversation View

                                                                                                              You receive a series of emails back and forth with a client regarding a project update. Instead of searching through your inbox for each separate email, you would want to see the entire email conversation in one place to understand the context quickly
                                                                                                            • Introducing Zoho PDF Editor: Your free online PDF editing tool

                                                                                                              Edit your PDFs effortlessly with Zoho PDF Editor, Zoho's new free online PDF editing tool. Add text, insert images, include shapes, embed hyperlinks, and even transform your PDFs into fillable forms to collect data and e-signatures. You can edit PDFs
                                                                                                            • RSC Connectivity Linkedin Recruiter RPS

                                                                                                              It seems there's a bit of a push from Linkedin Talent Solutions to keep integrations moving. My Account Manager confirmed that Zoho Recruit is a Certified Linkedin Linkedin Partner but does not have RSC as of yet., (we knew that :-) She encouraged me
                                                                                                            • Water-Scrum-Fall approach for finance institutions with Zoho Projects Plus

                                                                                                              Finance is a highly regulated sector with strict rules and compliance requirements. Handling sensitive client data and complex transactions like multi-currency deals requires elaborate workflows and precise management. Implementing project management
                                                                                                            • Get instant summaries of your notes with the help of Zia

                                                                                                              Hello all, We've added a simple yet powerful feature to Zoho CRM that we're excited for you to try: Zia Notes Summary. It's designed to make the daily lives of a CRM user a bit easier by giving you quick summaries of your CRM notes. Whether it's a glance
                                                                                                            • Zoho one web page are not available

                                                                                                              Why I am not able to enter to zoho one web page?
                                                                                                            • Zoho People > Onboarding > Candidate do not view all the data field on the Employee Onboarding

                                                                                                              Hello In my onboarding portal I do not see all the fields that i want the candidate to fill in In my Employee Onboarding Form These details i can see In the work information, i have enable the Company View but in the Employee Portal i do not see I have
                                                                                                            • Has anyone implemented a ""switch"" to redirect emails in production for testing?

                                                                                                              Hi everyone, In our production Zoho CRM we have a fairly complex setup with multiple Blueprints and Deluge functions that send emails automatically — to managers and internal staff — triggered by workflows. We’re looking for a way to *test changes safely*,
                                                                                                            • Restrict Access/Shared Access

                                                                                                              Sometimes access to documents that go out from Zoho Sign need to be restricted or shared. For example: 1) HR department send out employment contracts. Any Zoho Sign admin can view them. Access should be restricted to those that HR would allow to view
                                                                                                            • Tip#44: Integrate with Xero to manage your financial operations

                                                                                                              Managing your project finances becomes more efficient with Xero integration in Zoho Sprints. With this integration, you can sync your Zoho Sprints data with Xero. Once you sync them to Xero, you can easily create invoices in Xero. This feature significantly
                                                                                                            • Zoho People Onboarding Unable to Convert to User

                                                                                                              Hello All I need help in this onboarding of candidate Currently at this stage the candidate is just being offered and we are filling in his details however not all information are fill up. The candidate is still using his/her personal email When i try
                                                                                                            • Integration with SharePoint Online

                                                                                                              Is there an integration where we can add a Zoho Sign link to the context menu of a document in the SharePoint document library. Then, we could directly initiate a workflow of sending a document for signature from a document library in SharePoint onl
                                                                                                            • White screen when connecting Zoho Cliq and Zoho People for birthday notifications

                                                                                                              Hi everyone, I'm new to Zoho and I'm trying to set up the employee birthday notifications, following this guide: Automating Employee Birthday Notifications in Zoho Cliq But when I try to connect Zoho Cliq with Zoho People, I just get a white screen and
                                                                                                            • Word file is messed up when i upload it to zoho sign

                                                                                                              Hi. I am trying to upload a word file to zoho sign and when i do that it ruins the file, It adds spaces and images are on top of each other. What can i do? Thanks.
                                                                                                            • Annotate widget?

                                                                                                              Is there something in creator or any zoho app that allows me to have an image markup field item in the form? I need to be able to complete a form that also allows the user to mark up a preloaded image. Other compay's call this an image markup field or
                                                                                                            • Dashboards / Home Page - Logged In User

                                                                                                              Lots of the dashboards that we use reference the Logged In User.  We also set up Home Pages for specific roles, where the Logged In User is referenced within the custom view.  As an admin, that means that these views are often blank when customizing and
                                                                                                            • I'm pissed as fuck

                                                                                                              What the hell Zoho! Always the same goddam problem. It takes time because the simplest things just don't fucking work. Today it just took me 3 hours to complete and send a 1page privacy letter to a client. And you know what 99% of the document was already
                                                                                                            • Configure Notifications for API Limit

                                                                                                              Hello developers, APIs are essential for businesses today as they enable seamless integration between different software systems, automate workflows, and ensure real-time data sync. To ensure that admins are notified well in advance before APIs reach
                                                                                                            • Introducing Blueprints for Custom Modules!

                                                                                                              Hello developers, We've added a new feature called Blueprints in Custom Modules. Blueprints are the online representation of a business process. In Zoho Books, you can use Blueprints to design a process flow using states and transitions. Developers can
                                                                                                            • Campaign Links Blocked as Phishing- Help!

                                                                                                              We sent a Campaign out yesterday. We tested all of the links beforehand. One of the links is to our own website. After the fact, when we open up the Campaign in our browser, the links work fine. The links in the emails received, however, opened in a new
                                                                                                            • Zoho Tables July 2025 Update: Smart Creation, Smarter Automation

                                                                                                              We’re excited to introduce a powerful set of updates across Web, Android and iOS/iPad apps. From AI-assisted base creation to advanced automations and mobile enhancements, this release is packed with features to help you build faster, automate better,
                                                                                                            • Zoho Voice est désormais en France !

                                                                                                              Nous avons des nouveautés très intéressantes qui vont transformer la façon dont vous communiquez avec vos clients. Zoho Voice, la solution de téléphonie d'entreprise et de centre de contact basée sur le cloud est arrivée en France ! Vous pouvez enfin
                                                                                                            • Numbers in MA

                                                                                                              I have an issue rationalising the various numbers around MA2. Not convinced that any are truly accurate. However have a specific problem in that i have a list with 1301 records in the list view. When i come to email there is only 1289 Then have another
                                                                                                            • Android mobile app unable to log in

                                                                                                              When I open the mobile up for zoho mail it asks me to sign in, but when i push the sign in button nothing happens. Tried uninstalling and reinstalling still not working
                                                                                                            • Pie chart in Zoho Analytics shows ridicoulous numer of decimals of a percentage.

                                                                                                              Is there a way to set the number of decimals of a percentage value in the Pie chart? Now it displays 15 decimals instead of a round-off value. The value is a count and percentage calculated in the chart, so there is no number of decimals that can be specified
                                                                                                            • Zoho People > Leave Management > Unable to import balance leave

                                                                                                              Hello Zoho I am unable to import balance leave into the system I have follow the steps It show only 5 fields - the date field i am unable to select from date and to date Error Date in excelsheet
                                                                                                            • Narrative 4: Exploring the support channels

                                                                                                              Behind the scenes of a successful ticketing system - BTS Series Narrative 4 - Exploring the support channels Support channels in a ticketing system refer to the various communication methods that customers use to contact a business for assistance. These
                                                                                                            • Tip of the Week #65– Share email drafts with your team for quick feedback.

                                                                                                              Whether you're replying to a tricky customer question or sharing a campaign update, finding the right words—and the right tone—can be tough. You just wish your teammates could take a quick look and give their suggestions before you send it. Sometimes,
                                                                                                            • Next Page