0
# SDK Initialization
1
2
The Zoho CRM SDK initialization system provides centralized configuration management with support for multiple users, environments, token stores, and advanced configurations like logging and proxy settings.
3
4
## Capabilities
5
6
### Initialize SDK
7
8
Primary SDK initialization with all configuration options.
9
10
```javascript { .api }
11
/**
12
* Initialize the Zoho CRM SDK with comprehensive configuration
13
* @returns Promise that resolves when initialization is complete
14
*/
15
class InitializeBuilder {
16
/** Set the user signature for CRM operations */
17
user(user: UserSignature): InitializeBuilder;
18
/** Set the data center environment */
19
environment(environment: Environment): InitializeBuilder;
20
/** Set the authentication token */
21
token(token: Token): InitializeBuilder;
22
/** Set the token storage mechanism */
23
store(store: TokenStore): InitializeBuilder;
24
/** Set SDK configuration options */
25
SDKConfig(config: SDKConfig): InitializeBuilder;
26
/** Set the resource path for storing user-specific files */
27
resourcePath(path: string): InitializeBuilder;
28
/** Set the logger instance */
29
logger(logger: Logger): InitializeBuilder;
30
/** Set proxy configuration for API requests */
31
requestProxy(proxy: RequestProxy): InitializeBuilder;
32
/** Execute the initialization */
33
initialize(): Promise<void>;
34
/** Switch to a different user configuration */
35
switchUser(): Promise<void>;
36
}
37
```
38
39
**Usage Example:**
40
41
```javascript
42
const { InitializeBuilder } = require("@zohocrm/nodejs-sdk-2.0/routes/initialize_builder");
43
const { UserSignature } = require("@zohocrm/nodejs-sdk-2.0/routes/user_signature");
44
const { OAuthBuilder } = require("@zohocrm/nodejs-sdk-2.0/models/authenticator/oauth_builder");
45
const { USDataCenter } = require("@zohocrm/nodejs-sdk-2.0/routes/dc/us_data_center");
46
const { FileStore } = require("@zohocrm/nodejs-sdk-2.0/models/authenticator/store/file_store");
47
const { LogBuilder } = require("@zohocrm/nodejs-sdk-2.0/routes/logger/log_builder");
48
const { Levels } = require("@zohocrm/nodejs-sdk-2.0/routes/logger/logger");
49
const { SDKConfigBuilder } = require("@zohocrm/nodejs-sdk-2.0/routes/sdk_config_builder");
50
51
async function initializeSDK() {
52
// Create user signature
53
const user = new UserSignature("user@example.com");
54
55
// Set environment
56
const environment = USDataCenter.PRODUCTION();
57
58
// Configure OAuth token
59
const token = new OAuthBuilder()
60
.clientId("your_client_id")
61
.clientSecret("your_client_secret")
62
.refreshToken("your_refresh_token")
63
.redirectURL("your_redirect_url")
64
.build();
65
66
// Setup token storage
67
const tokenStore = new FileStore("/path/to/tokens.txt");
68
69
// Configure logging
70
const logger = new LogBuilder()
71
.level(Levels.INFO)
72
.filePath("/path/to/sdk_logs.log")
73
.build();
74
75
// SDK configuration
76
const sdkConfig = new SDKConfigBuilder()
77
.autoRefreshFields(true)
78
.pickListValidation(true)
79
.build();
80
81
// Initialize
82
await new InitializeBuilder()
83
.user(user)
84
.environment(environment)
85
.token(token)
86
.store(tokenStore)
87
.SDKConfig(sdkConfig)
88
.resourcePath("/path/to/resources")
89
.logger(logger)
90
.initialize();
91
}
92
```
93
94
### User Signature
95
96
Represents a CRM user identity for API operations.
97
98
```javascript { .api }
99
/**
100
* Represents a user in the CRM system
101
*/
102
class UserSignature {
103
/** Create a user signature with email */
104
constructor(email: string);
105
/** Get the user's email address */
106
getEmail(): string;
107
}
108
```
109
110
### Multi-User Support
111
112
Switch between different user configurations without re-initializing the entire SDK.
113
114
```javascript { .api }
115
/**
116
* Switch to a different user configuration
117
*/
118
class InitializeBuilder {
119
/** Switch to different user context */
120
switchUser(): Promise<void>;
121
}
122
123
/**
124
* Remove a user's configuration from the SDK
125
* @param user - The user to remove
126
* @param environment - The environment to remove the user from
127
*/
128
class Initializer {
129
static removeUserConfiguration(user: UserSignature, environment: Environment): Promise<void>;
130
}
131
```
132
133
**Multi-User Usage Example:**
134
135
```javascript
136
const { InitializeBuilder } = require("@zohocrm/nodejs-sdk-2.0/routes/initialize_builder");
137
const { Initializer } = require("@zohocrm/nodejs-sdk-2.0/routes/initializer");
138
139
// Initialize first user
140
const user1 = new UserSignature("user1@example.com");
141
const token1 = new OAuthBuilder()
142
.clientId("client_id_1")
143
.clientSecret("client_secret_1")
144
.refreshToken("refresh_token_1")
145
.redirectURL("redirect_url_1")
146
.build();
147
148
await new InitializeBuilder()
149
.user(user1)
150
.environment(USDataCenter.PRODUCTION())
151
.token(token1)
152
.initialize();
153
154
// Perform operations as user1...
155
156
// Switch to second user
157
const user2 = new UserSignature("user2@example.com");
158
const token2 = new OAuthBuilder()
159
.clientId("client_id_2")
160
.clientSecret("client_secret_2")
161
.refreshToken("refresh_token_2")
162
.redirectURL("redirect_url_2")
163
.build();
164
165
await new InitializeBuilder()
166
.user(user2)
167
.environment(EUDataCenter.SANDBOX())
168
.token(token2)
169
.switchUser();
170
171
// Perform operations as user2...
172
173
// Remove user1 configuration
174
await Initializer.removeUserConfiguration(user1, USDataCenter.PRODUCTION());
175
```
176
177
### SDK Configuration
178
179
Advanced SDK behavior configuration.
180
181
```javascript { .api }
182
/**
183
* SDK configuration options
184
*/
185
class SDKConfig {
186
/** Whether to auto-refresh module fields in the background */
187
autoRefreshFields: boolean;
188
/** Whether to validate picklist values */
189
pickListValidation: boolean;
190
}
191
192
/**
193
* Builder for SDK configuration
194
*/
195
class SDKConfigBuilder {
196
/** Enable/disable automatic field refresh (default: false) */
197
autoRefreshFields(autoRefreshFields: boolean): SDKConfigBuilder;
198
/** Enable/disable picklist validation (default: true) */
199
pickListValidation(pickListValidation: boolean): SDKConfigBuilder;
200
/** Build the configuration */
201
build(): SDKConfig;
202
}
203
```
204
205
### Logging Configuration
206
207
Comprehensive logging setup with configurable levels and file output.
208
209
```javascript { .api }
210
/**
211
* Logger configuration builder
212
*/
213
class LogBuilder {
214
/** Set logging level */
215
level(level: LogLevel): LogBuilder;
216
/** Set log file path */
217
filePath(filePath: string): LogBuilder;
218
/** Build the logger */
219
build(): Logger;
220
}
221
222
/**
223
* Available logging levels
224
*/
225
class Levels {
226
static ERROR: LogLevel;
227
static WARN: LogLevel;
228
static INFO: LogLevel;
229
static HTTP: LogLevel;
230
static VERBOSE: LogLevel;
231
static DEBUG: LogLevel;
232
static SILLY: LogLevel;
233
}
234
```
235
236
### Proxy Configuration
237
238
HTTP proxy support for API requests.
239
240
```javascript { .api }
241
/**
242
* HTTP proxy configuration
243
*/
244
class RequestProxy {
245
host: string;
246
port: number;
247
user?: string;
248
password?: string;
249
}
250
251
/**
252
* Builder for proxy configuration
253
*/
254
class ProxyBuilder {
255
/** Set proxy host */
256
host(host: string): ProxyBuilder;
257
/** Set proxy port */
258
port(port: number): ProxyBuilder;
259
/** Set proxy username (optional) */
260
user(user: string): ProxyBuilder;
261
/** Set proxy password (optional) */
262
password(password: string): ProxyBuilder;
263
/** Build the proxy configuration */
264
build(): RequestProxy;
265
}
266
```
267
268
**Proxy Usage Example:**
269
270
```javascript
271
const { ProxyBuilder } = require("@zohocrm/nodejs-sdk-2.0/routes/proxy_builder");
272
273
const proxy = new ProxyBuilder()
274
.host("proxy.company.com")
275
.port(8080)
276
.user("proxy_user")
277
.password("proxy_password")
278
.build();
279
280
await new InitializeBuilder()
281
.user(user)
282
.environment(environment)
283
.token(token)
284
.requestProxy(proxy)
285
.initialize();
286
```
287
288
### Parameter and Header Management
289
290
Utilities for managing API request parameters and headers.
291
292
```javascript { .api }
293
/**
294
* Manages query parameters for API requests
295
*/
296
class ParameterMap {
297
/** Add a parameter to the map */
298
add(param: Param, value: any): Promise<void>;
299
}
300
301
/**
302
* Manages HTTP headers for API requests
303
*/
304
class HeaderMap {
305
/** Add a header to the map */
306
add(header: Header, value: any): Promise<void>;
307
}
308
309
/**
310
* Represents a query parameter
311
*/
312
class Param {
313
constructor(name: string, className: string);
314
}
315
316
/**
317
* Represents an HTTP header
318
*/
319
class Header {
320
constructor(name: string, className: string);
321
}
322
```