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

                                                                                                            • How to Initiate WhatsApp Message on SalesIQ?

                                                                                                              I've just activated a Business WhatsApp phone number through SalesIQ because of its touted omnichannel chat approach. Sounds exciting. I understand that when a customer sends me a WA message, I can reply to it on SalesIQ and keep the chat going, perfect.
                                                                                                            • Episode IV:Handling User Inputs in custom functions

                                                                                                              Hi Everyone, We've been exploring custom functions which help in performing advanced automation tasks. Custom functions enable you to achieve possibilities based on your organization's requirements. Custom functions require user inputs that allow the
                                                                                                            • Set a lead as non-marketing if they opt out of email marketing

                                                                                                              I'm gathering Lead data via an enquiry form and wish to give them the option to opt out of marketing emails (which we send from Marketing Automation) whilst retaining the ability to send them non-marketing emails - so the email opt-out field doesn't work.
                                                                                                            • Set up multiple IMAP email addresses

                                                                                                              Hi, I just started using CRM and its great, but I just found out I can only add one imap email address for incoming mail in the included salesinbox ...this is ridiculous. All companies have different email such as sales@domain, info@domain , personal@domain
                                                                                                            • Zoho Recruit to Zoho People integration

                                                                                                              In the mapping of field from Zoho Recruit to Zoho People i am unable to map all fields What can i do
                                                                                                            • Zoho Recruit > Career Site > Customisation

                                                                                                              Hi All I have created multiple career site to represent my different organization In my Quanta Media career site > I set it with the with Quanta Malta view In my job opening : Quanta Malta view 2 job opening In my URL for quanta media https://lri.zohorecruit.eu/jobs/Quanta-Malta
                                                                                                            • Formatting Blueprint Stages (buttons)

                                                                                                              Is there a way to format Blueprint transition buttons in Creator like background colour, text colour etc.
                                                                                                            • Disable Default Value in Multi-Select field

                                                                                                              Hello, Is there a way to disable the default value feature when setting up a custom Multi-Select field? When creating tickets I would like it so there isn't a value pre-selected in the multi-select custom field that was created.
                                                                                                            • How to set custom business hours for different teams in Zoho Desk?

                                                                                                              Hi Zoho Team and Community, I’m trying to set different business hours for multiple departments in Zoho Desk. For example, our tech support team works 24/7, while our billing team is only available from 9 AM to 5 PM (Mon–Fri). Is there a way to assign
                                                                                                            • Zia Auto Tag Keyword Clusters

                                                                                                              Is there a way to remove a keyword from a keyword cluster? We're finding that Zia auto-tag is tagging things incorrectly based on some words that don't really make sense.
                                                                                                            • Centralized Domain Verification in Zoho CRM Plus

                                                                                                              Hi Team, I have a suggestion regarding Zoho CRM Plus. It's quite frustrating to verify the same domain separately for each application within the suite. It would be really helpful if you could introduce a centralized admin console—similar to what's available
                                                                                                            • HOw do I make a refund?

                                                                                                              I have a client that needs a refund. I see a refund history in the Report area... but where do I go to make a refund?
                                                                                                            • Creating a work order for dispatch

                                                                                                              We currently uses ZOHO for CRM and Intuit Field Service for creating Work orders and dispatching. This is causing double entry and is not efficient use of time.  I would like to use ZOHO for all customer related activities so can you tell me if you can :  Create a work order that we could manipulate to meet our needs.  Also if you could then dispatch that would be ideal. Thank you
                                                                                                            • "code": "500","description": "Account not exists", mail api

                                                                                                              I have been through all the steps and have a functioning Oath access_token etc etc... I then GET https://mail.zoho.com/api/organization And get my zoid then GET http://mail.zoho.com/api/organization/<hidden>/accounts and get the account details, which
                                                                                                            • Residual Formatting in Text Boxes After Undoing Pasting of Formatted Text

                                                                                                              Hi, guys! I have another problem to report. Actually, I have been aware of this for many months, possibly years, but I have been too lazy to report it to you. My apologies! Let's say you've pasted a formatted string into a text box. You change your mind
                                                                                                            • Feature Request: Stripe Terminal Integration

                                                                                                              I would like to request the addition of Stripe Terminal integration to Zoho Books, which will help process in-person payments. While Zoho Books already supports online payments through Stripe, extending this functionality to include Stripe Terminal would
                                                                                                            • Customer Parent Account or Sub-Customer Account

                                                                                                              Some of clients as they have 50 to 300 branches, they required separate account statement with outlet name and number; which means we have to open new account for each branch individually. However, the main issue is that, when they make a payment, they
                                                                                                            • Improved Security in SAML/OIDC Sign-in Redirection Flow

                                                                                                              To enhance the security of our authentication system, we’ve made a change to how SAML and OIDC sign-in redirections are handled. This update resolves a potential open redirection vulnerability and adds an extra layer of protection during the sign-in process.
                                                                                                            • GA4 data

                                                                                                              Hi, I have data being pulled from GA4 into numerous tables. There are a few major errors in the source data. Eg for a period of time GA4 reported ecommerce sales that were $98 as $9,800 and $42 as $4,200. It's not happening now but my historical data
                                                                                                            • Ask the Experts: Five-hour live Q&A session with Zoho WorkDrive product experts

                                                                                                              Have questions about WorkDrive 5.0? Let’s talk! We recently launched Zoho WorkDrive 5.0, packed with powerful updates to help your team work smarter, stay secure, and get more value from your business content. From content-centric workflows and AI-powered
                                                                                                            • Allow the usage of Multi-Select fields as the primary field on "Layout Rules"

                                                                                                              We want to force our users to enter some explanation strings when a multi-select field has been utilized. I can't understand the reason for the usage restriction of Multi-Select fields as a primary field. This is a simple "Display hidden mandatory field
                                                                                                            • Lost Search Box with new UI Design

                                                                                                              I would like to suggest bringing back the Search Box in the new Zoho Project UI.  I use the search feature a lot and having to click the magnifying glass to type for a search is one extra click that we did not have with the old UI.
                                                                                                            • Adaptación de zoho books a la nueva regulación de facturación electrónica

                                                                                                              La facturación electrónica será obligatoria para todas las empresa en España en 2025, en Francia probablemente también e imagino pronto en todos los países europeos. Ya en 2024 todas las empresa grandes tienen que utilizar el sistema de facturación electrónica.
                                                                                                            • ZOHOBOOK Sales_QUOTE: To Add Discount At Each Line Item Table

                                                                                                              Hi, Our quote need to display with discount at each line item level as well. Try to edit template, >CUSTOMISE>EDIT TEMPLATE> Table, I can see template view with discount column, but when hit SAVE the template, view in PDF the discount column not shown.
                                                                                                            • How to account for vat with postponed VAT accounting

                                                                                                              Hi everyone, looking for some help with postponed VAT accounting, I use DHL express for my imports and they used to pay the VAT for me and then invoice me. I could then log this as a bill and the VAT element from import was recorded as input VAT, all
                                                                                                            • Weekly Automation Trigger for Equipment Calibration Reminder

                                                                                                              Dear Team, I’m currently working on an automation in the Equipment module. The goal is to track calibration schedules for tools — all of which require regular calibration. I’ve created an automation that sends email reminders for tools that are due for
                                                                                                            • Want to use Zoho Books in Switzerland. CHF support planned?

                                                                                                              Hi, We're a Swiss company using other Zoho suite software and I discovered Zoho Books and other accounting SaaS when looking for an accounting tool. Do you intend to cover Switzerland and CHF based accounting anytime soon? Roy
                                                                                                            • ADDDATE formula using 2 calculations

                                                                                                              Hello, I want to create an ADDDATE formula using 2 calculations, add 1 month and deduct 1 day. the formula that I need should look like this: ADDDATE(due_date, 1, "Months")+ ADDDATE(due_date, -1, "Days") Each row itself works fine, but when I'm trying
                                                                                                            • Upgrading from Zoho Invoice to Books was a major downgrade in functionality for me

                                                                                                              I have been a user for many years of a free plan on Zoho Invoice for my personal consulting business. I recent upgraded my organization to Books since some of the additional functionality looked useful to me, and played around with the free trial for
                                                                                                            • 🎉 Dynamic Org Chart for Zoho CRM Extension Published [2025]

                                                                                                              Hey Zoho CRM Community! We're thrilled to unveil our latest Zoho extension:🥁 Dynamic Org Chart for Zoho CRM 🎊 This extension is now available to transform the way your teams visualize, manage, and interact with org chart directly inside any Zoho CRM's
                                                                                                            • Detailed General Ledger has problem of exporting out to excel and missing ledger details for some accounts

                                                                                                              I have been encountering some problems generating Detailed General Ledger report with Zoho books. Firstly, I cannot export out the report of Detailed General Ledger to Excel. It will show this error message "invalid value passed for sort column", and
                                                                                                            • Upload a file to a File Upload Field through API

                                                                                                              Hello, Is there any way to upload a file to a custom file upload field in a module when doing an Update using the Record API? I've found and I am able to upload files to attachments but I don't know how to upload them to a field. I've checked the documentation at  https://www.zoho.com/crm/help/api/v2/#update-specify-records but the File Upload field type does not appear in the examples. Thanks
                                                                                                            • Kaizen #131 - Bulk Write for parent-child records using Scala SDK

                                                                                                              Hello and welcome back to this week's Kaizen! Last week, we discussed how to configure and initialize the Zoho CRM Scala SDK. This week, we will be exploring the Bulk Write API and its capabilities. Specifically, we will focus on executing bulk write
                                                                                                            • Automatic pricing feature for sales orders

                                                                                                              I am currently setting up my Zoho Inventory system and would like to implement an automatic pricing feature for sales orders. We have created a custom field called "brandline" for our items. All products with the same brandline value should have the same
                                                                                                            • Ability to access VAT returns and submit them has disappeared.

                                                                                                              I have been using Zoho books successfully to submit quarterly VAT returns. Without reason I have lost that facility. I have followed all available instructions eg going into settings, taxes, VAT etc. without success. My registration number is there and
                                                                                                            • How to automatically schedule a meeting After Blueprint Transition

                                                                                                              As part of our sales process, we require a technician to go to the customer's site and perform an installation prior to advancing to the next stage of the blueprint.  So this will require (a) scheduling a meeting for the technician to visit the customer's site and (b) a reminder phone call the day before the scheduled meeting. As I'm designing the Deal Blueprint, I see that I can automatically add a Task to the deal, but I can't add a Meeting or a Call. What am I missing?  There seem to be 3 types
                                                                                                            • Zoho Recruit > Workflow

                                                                                                              I have created a workflow for my application module Whenever a record is created The condition , application status is 1st call invitation I have set this OI do not receive the email that was suppose to be send out
                                                                                                            • [Webinar] Zoho Writer for SCM and logistics

                                                                                                              Creating, sharing, and distributing complex documents are constant challenges in the SCM and logistics industry. That's why our next webinar is focused on how to simplify these document workflows. Join us on Jul 10, 2025 for a Zoho Writer webinar designed
                                                                                                            • Multiple locations but one parent company

                                                                                                              I am trying to configure my accounts that have multiple locations under one parent company to show separate locations in the portal.   
                                                                                                            • Stock Count History in Product Details – Zoho Inventory

                                                                                                              Hello Zoho Team, When I perform a Stock Count for a product in Zoho Inventory, I would like to view the history of those stock counts later — especially from the product details page. Currently, I can perform the count and update the quantity, but I’m
                                                                                                            • Next Page