You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node SDK is a wrapper for Zoho CRM APIs. Hence invoking a Zoho CRM API from your Node application is just a function call which provide the most appropriate response.
6
6
7
7
This SDK supports both single user as well as multi user authentication.
8
8
9
-
##Registering a Zoho Client
9
+
##Registering a Zoho Client
10
10
11
11
Since Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:
12
12
13
-
- Visit this page https://accounts.zoho.com/developerconsole.
13
+
- Visit this page https://accounts.zoho.com/developerconsole.
14
+
- Click on “Add Client ID”.
15
+
- Enter Client Name, Client Domain and Redirect URI.
16
+
- Select the Client Type as "Web based".
17
+
- Click “Create”.
18
+
- Your Client app would have been created and displayed by now.
19
+
- The newly registered app's Client ID and Client Secret can be found by clicking Options → Edit. (Options is the three dot icon at the right corner).
14
20
15
-
- Click on “Add Client ID”.
16
-
17
-
- Enter Client Name, Client Domain and Redirect URI.
18
-
19
-
- Select the Client Type as "Web based".
20
-
21
-
- Click “Create”.
22
-
23
-
- Your Client app would have been created and displayed by now.
24
-
25
-
- The newly registered app's Client ID and Client Secret can be found by clicking Options → Edit. (Options is the three dot icon at the right corner).
26
-
27
-
##Installation of Node CRM SDK
21
+
## Installation of Node CRM SDK
28
22
29
23
Node JS SDK will be installed and a package named 'zcrmsdk' will be created in the installation directory.
30
24
31
-
>npm install zcrmsdk
25
+
```console
26
+
npm install zcrmsdk
27
+
```
32
28
33
29
Once installed it can be used in the code as below,
34
30
35
-
>var ZCRMRestClient = require('zcrmsdk')
36
-
37
-
##API Usage
31
+
```javascript
32
+
var ZCRMRestClient =require('zcrmsdk')
33
+
```
38
34
39
-
##Configurations
35
+
##Configurations
40
36
41
37
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/ package from where the SDK is used.
42
38
43
-
44
-
zcrmsdk will try reading file from **'resources/oauth_configuration.properties'**
45
-
39
+
zcrmsdk will try reading file from `'resources/oauth_configuration.properties'`
46
40
47
41
Please fill the values for the following keys alone.
48
42
Based on your domain(EU,CN), please change the value of crm.iamurl. Default value set as US domain.
49
43
50
-
51
-
```
52
-
44
+
```ini
53
45
[zoho]
54
-
crm.iamurl=
55
-
crm.clientid=
56
-
crm.clientsecret=
57
-
crm.redirecturl=
58
-
46
+
crm.iamurl=
47
+
crm.clientid=
48
+
crm.clientsecret=
49
+
crm.redirecturl=
59
50
```
60
51
61
-
crm.clientid, crm.clientsecret and crm.redirecturl are your OAuth client’s configurations that you get after registering your Zoho client.
62
-
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.
52
+
`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 `crm.iamurl` is not specified, the default URL will be `accounts.zoho.com`.
63
53
64
-
In configuration.properties file:
54
+
In `configuration.properties` file:
65
55
66
-
```
56
+
```ini
67
57
[crm]
68
-
api.url=
69
-
api.user_identifier=
70
-
api.tokenmanagement=
58
+
api.url=
59
+
api.user_identifier=
60
+
api.tokenmanagement=
71
61
72
62
[mysql]
73
63
username=
74
-
password=
75
-
64
+
password=
76
65
```
77
-
api.url is the URL used to call APIs. By default, the URL is www.zohoapis.com.
78
-
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.
79
-
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.
80
-
username and password can be given here if you already have one created for your MySQL.
81
-
The above keys specified in configuration.properties file are all optional.
82
-
83
-
user_identifier can be set in two ways .
84
-
1.Mentioning it in api.user_identifier in configuration.properties file
85
-
2.Can be set via code using set setUserIdentifier.
66
+
`api.url` is the URL used to call APIs (default `www.zohoapis.com`).
67
+
`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 API calls use this user's authentication.
68
+
`api.tokenmanagement` can be used to provide an alternative token storage function. If not specified the default implementation (MySQL) will be used.
69
+
`username` and `password` are the credentials used to access MySQL
70
+
The above keys specified in `configuration.properties` file are all optional.
86
71
87
-
If user_identifier is not set via both the ways then default value 'zcrm_default_user' will be set by the sdk itself .
72
+
`user_identifier` can be set by either:
73
+
1. Specifying `api.user_identifier` in the `configuration.properties` file or
74
+
1. Via code by using set `setUserIdentifier()`
88
75
76
+
If `user_identifier` is not set the default value (`zcrm_default_user`) will be used.
89
77
90
-
##Token Storage Mechanism
91
78
92
-
To use the default token storage provided by the SDK, the following are to be done:
79
+
## Token Storage Mechanism
93
80
94
-
**Mysql should be running in default port in localhost.**
81
+
To use the default token storage mechanism:
82
+
**MySQL should be running on the default port (3306) on localhost.**
83
+
Create a database named `zohooauth` with a table named `"oauthtokens"` with the columns `"useridentifier" (varchar), "accesstoken" (varchar), "refreshtoken" (varchar), and "expirytime" (bigint)`.
95
84
96
-
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)**.
85
+
With this configuration in place, storage and retrieval of tokens will be handled by the SDK.
97
86
98
-
Once the configuration is set, storage and retrieval of tokens will be handled by the SDK.
99
-
If the user wants to utilize their own mechanism, they can mention it in configuration.properties by providing the respective module in api.tokenmanagement.
87
+
### Custom Token Storage
88
+
If you want to use another token storage mechanism, you can declare it in `configuration.properties` by specifying the respective module in `api.tokenmanagement`.
100
89
101
-
This module should contain the below methods,
102
-
**saveOAuthTokens(token_obj)**
103
-
**updateOAuthTokens(token_obj)**
104
-
Irrespective of response, the next execution happens. So care should be taken by the user in handling their module.
105
-
**getOAuthTokens()**
106
-
The expected response for this method : JSON array containing json response with expirytime, refreshtoken and accesstoken fields.
90
+
This module should contain the methods:
91
+
-`saveOAuthTokens(token_obj)`
92
+
-`updateOAuthTokens(token_obj)`
93
+
-`getOAuthTokens()` - shall return a JSON array containing expirytime, refreshtoken and accesstoken fields.
107
94
108
-
109
-
##Generating self-authorized grant and refresh token
95
+
## Generating self-authorized grant and refresh token
110
96
111
97
For self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)
- Click Options → Self Client of the client for which you wish to authorize.
117
-
118
-
- 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.
119
-
- Copy the grant token for backup.
120
-
121
-
- 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
- Click Options → Self Client of the client for which you wish to authorize.
101
+
- 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.
102
+
- Copy the grant token for backup.
103
+
- 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
104
+
- Copy the refresh token for backup.
124
105
125
106
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.
126
107
@@ -129,7 +110,7 @@ Each time server is restarted, this function has to be called and both the confi
129
110
**All functions return promises in zcrm node sdk.**
130
111
131
112
132
-
##Initialize
113
+
##Initialize
133
114
134
115
Below snippet has to be called before starting the app
As appearing in the hierarchy, zcrmsdk entity class has instance variables to fetch its own properties and to fetch data of its immediate child entities through an API call.
253
229
254
230
For example, to call an API to get module data, the request should be zcrmsdk.API.MODULES.{operation_type}. The operation types can be GET, POST, PUT, DELETE or CREATE.
255
231
256
-
257
-
258
-
##Response Handling
232
+
## Response Handling
259
233
All API calls will give the actual API response given by Zoho APIs, except file download.
260
234
261
235
For file download, the response will contain an extra field filename.
262
236
263
-
##Error Handling:
264
-
All errors will be thrown explicitly and care should be taken in catching the same.
265
-
266
-
267
-
237
+
## Error Handling:
238
+
All errors will be thrown explicitly and care should be taken to catch them.
0 commit comments