Setting up Zoho CRM Node JS SDK (Self Client)
For this tutorial in video form, check out the companion Youtube video.
You’ll also probably want to check out the code I use.
In this post, I’m going to show you how to use the Node JS SDK for Zoho CRM. There’s a lot of content on the actual documentation page, but a lot of it’s not really that helpful if you’re just trying to write some node JS code that will communicate with your own CRM account. If you are building an app that needs to get data out of multiple CRM accounts, stick to the docs page but if your ambitions are limited to your own company’s data, read on.
Basically you can ignore everything that it says on the page until about halfway down where it talks about a Self Client.
Our goal will be to add CRM integration functionality to an AWS Lambda function a Node JS web server so we can push and pull data from our own CRM.
Head over to api-console.zoho.com and create a new Self Client.
Choose appropriate API scopes (e.g. ZohoCRM.bulk.all allows you to do most API calls) making sure to include “aaaserver.profile.ALL” which is required for use with the SDK.
After you click Create, it will give you a grant token which you can put in a .env file. You’ll also click on the Client Secret tab and grab the client ID and client secret.
We should then be able to generate an oauth access token + refresh token using ZCRMRestClient.generateAuthTokens. (Get the code from the github repo)
You can see that worked, and now there’s a file here with an access_token and refresh_token.
The refresh token we just generated is a long lived credential which we can use to generate new access tokens.
You can generate the refresh token locally and then store it as a secret on your server and happily authenticate with the CRM APIs forevermore.
Let’s now make sure that the access token actually works: can we get data about the CRM’s modules via the SDK?
The way we set up the self client previously isn’t going to fly. We only allowed access to the record APIs not to the metadata APIs. We’ll need to recreate the self client with the appropriate OAuth scopes. First, we’ll take a look at the API documentation and figure out the right scope we need to give it, which is “ZohoCRM.settings.all.”
Then we recreate the self client and put in the new grant token. After that, instead of immediately running “testSDK,” we’re going to bootstrap it again and then we can get our module data.
You can see that it’s giving us all the information about the different modules that exist there, and we could theoretically run any other API method as well (after making sure we’ve selected the correct scopes)
Hopefully that helps you with this kind of use case where you are running a Node JS app and you only care about data in your own CRM. If you want to get data out of other people’s CRMs, we’ll handle that in another post.