0
# Bulk Operations
1
2
The Bulk Operations module provides high-volume data import and export capabilities for efficiently handling large datasets in Zoho CRM, including bulk read (export) and bulk write (import) operations.
3
4
## Capabilities
5
6
### Bulk Read Operations
7
8
Export large volumes of data from CRM modules with support for custom queries and filtering.
9
10
```javascript { .api }
11
/**
12
* Operations for bulk data export from CRM modules
13
*/
14
class BulkReadOperations {
15
/**
16
* Create a bulk read job for data export
17
* @param request - Request wrapper containing export specifications
18
* @returns Promise with APIResponse containing job creation results
19
*/
20
createBulkReadJob(request: RequestWrapper): Promise<APIResponse>;
21
22
/**
23
* Get details of a bulk read job including status and progress
24
* @param jobId - Unique identifier of the bulk read job
25
* @returns Promise with APIResponse containing job details
26
*/
27
getBulkReadJobDetails(jobId: string): Promise<APIResponse>;
28
29
/**
30
* Download the result file of a completed bulk read job
31
* @param jobId - Unique identifier of the bulk read job
32
* @returns Promise with APIResponse containing file download
33
*/
34
downloadResult(jobId: string): Promise<APIResponse>;
35
}
36
```
37
38
**Bulk Read Example:**
39
40
```javascript
41
const { BulkReadOperations } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_read/bulk_read_operations");
42
const { RequestWrapper } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_read/request_wrapper");
43
const { CallBack } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_read/call_back");
44
const { Query } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_read/query");
45
46
// Create bulk read job
47
const bulkReadOperations = new BulkReadOperations();
48
49
// Configure callback URL for job completion notification
50
const callback = new CallBack();
51
callback.setUrl("https://your-app.com/webhook/bulk-read");
52
callback.setMethod("post");
53
54
// Configure query
55
const query = new Query();
56
query.setModule("Leads");
57
query.setCriteria("(Created_Time:greater_than:2023-01-01T00:00:00+00:00)");
58
query.setFields(["Company", "Last_Name", "First_Name", "Email", "Phone"]);
59
60
// Create request
61
const requestWrapper = new RequestWrapper();
62
requestWrapper.setCallback(callback);
63
requestWrapper.setQuery(query);
64
65
// Submit job
66
const createResponse = await bulkReadOperations.createBulkReadJob(requestWrapper);
67
68
if (createResponse != null) {
69
const responseObject = createResponse.object;
70
if (responseObject instanceof ActionWrapper) {
71
const actionResponses = responseObject.getData();
72
actionResponses.forEach(actionResponse => {
73
if (actionResponse instanceof SuccessResponse) {
74
const jobId = actionResponse.getDetails().get("id");
75
console.log("Bulk Read Job ID: " + jobId);
76
}
77
});
78
}
79
}
80
81
// Check job status
82
const jobDetailsResponse = await bulkReadOperations.getBulkReadJobDetails("job_id_here");
83
84
// Download results when job is complete
85
const downloadResponse = await bulkReadOperations.downloadResult("job_id_here");
86
```
87
88
### Bulk Write Operations
89
90
Import large volumes of data into CRM modules with support for various file formats and data validation.
91
92
```javascript { .api }
93
/**
94
* Operations for bulk data import into CRM modules
95
*/
96
class BulkWriteOperations {
97
/**
98
* Upload a file for bulk import
99
* @param request - File body wrapper containing the file to upload
100
* @returns Promise with APIResponse containing file upload results
101
*/
102
uploadFile(request: FileBodyWrapper): Promise<APIResponse>;
103
104
/**
105
* Create a bulk write job for data import
106
* @param request - Request wrapper containing import specifications
107
* @returns Promise with APIResponse containing job creation results
108
*/
109
createBulkWriteJob(request: RequestWrapper): Promise<APIResponse>;
110
111
/**
112
* Get details of a bulk write job including status and progress
113
* @param jobId - Unique identifier of the bulk write job
114
* @returns Promise with APIResponse containing job details
115
*/
116
getBulkWriteJobDetails(jobId: string): Promise<APIResponse>;
117
118
/**
119
* Download the result file of a completed bulk write job
120
* @param jobId - Unique identifier of the bulk write job
121
* @returns Promise with APIResponse containing result file download
122
*/
123
downloadBulkWriteResult(jobId: string): Promise<APIResponse>;
124
}
125
```
126
127
**Bulk Write Example:**
128
129
```javascript
130
const { BulkWriteOperations } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_write/bulk_write_operations");
131
const { FileBodyWrapper } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_write/file_body_wrapper");
132
const { RequestWrapper } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_write/request_wrapper");
133
const { CallBack } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_write/call_back");
134
const { Resource } = require("@zohocrm/nodejs-sdk-2.0/core/com/zoho/crm/api/bulk_write/resource");
135
const fs = require("fs");
136
137
const bulkWriteOperations = new BulkWriteOperations();
138
139
// Step 1: Upload file
140
const fileStream = fs.createReadStream("path/to/leads_import.csv");
141
const fileWrapper = new FileBodyWrapper();
142
fileWrapper.setFile(fileStream);
143
144
const uploadResponse = await bulkWriteOperations.uploadFile(fileWrapper);
145
let fileId = null;
146
147
if (uploadResponse != null) {
148
const responseObject = uploadResponse.object;
149
if (responseObject instanceof ActionWrapper) {
150
const actionResponses = responseObject.getData();
151
actionResponses.forEach(actionResponse => {
152
if (actionResponse instanceof SuccessResponse) {
153
fileId = actionResponse.getDetails().get("file_id");
154
console.log("File uploaded with ID: " + fileId);
155
}
156
});
157
}
158
}
159
160
// Step 2: Create bulk write job
161
const callback = new CallBack();
162
callback.setUrl("https://your-app.com/webhook/bulk-write");
163
callback.setMethod("post");
164
165
const resource = new Resource();
166
resource.setType("data");
167
resource.setModule("Leads");
168
resource.setFileId(fileId);
169
resource.setIgnoreEmpty(true);
170
resource.setFindBy("Email"); // Unique field for upsert
171
172
// Configure field mappings
173
const fieldMappings = [
174
{ "api_name": "Company", "index": 0 },
175
{ "api_name": "Last_Name", "index": 1 },
176
{ "api_name": "First_Name", "index": 2 },
177
{ "api_name": "Email", "index": 3 },
178
{ "api_name": "Phone", "index": 4 }
179
];
180
resource.setFieldMappings(fieldMappings);
181
182
const requestWrapper = new RequestWrapper();
183
requestWrapper.setCharacterEncoding("UTF-8");
184
requestWrapper.setOperation("insert");
185
requestWrapper.setCallback(callback);
186
requestWrapper.setResource([resource]);
187
188
const createJobResponse = await bulkWriteOperations.createBulkWriteJob(requestWrapper);
189
190
// Step 3: Monitor job progress
191
const jobDetailsResponse = await bulkWriteOperations.getBulkWriteJobDetails("job_id_here");
192
193
// Step 4: Download results
194
const downloadResponse = await bulkWriteOperations.downloadBulkWriteResult("job_id_here");
195
```
196
197
### Bulk Read Data Models
198
199
Data models for configuring bulk read operations.
200
201
```javascript { .api }
202
/**
203
* Request wrapper for bulk read operations
204
*/
205
class RequestWrapper {
206
/** Get callback configuration */
207
getCallback(): CallBack;
208
/** Set callback configuration */
209
setCallback(callback: CallBack): void;
210
211
/** Get query configuration */
212
getQuery(): Query;
213
/** Set query configuration */
214
setQuery(query: Query): void;
215
216
/** Get file type for export */
217
getFileType(): string;
218
/** Set file type for export (csv, ics) */
219
setFileType(fileType: string): void;
220
}
221
222
/**
223
* Query configuration for bulk read
224
*/
225
class Query {
226
/** Get module to export from */
227
getModule(): string;
228
/** Set module to export from */
229
setModule(module: string): void;
230
231
/** Get export criteria */
232
getCriteria(): string;
233
/** Set export criteria */
234
setCriteria(criteria: string): void;
235
236
/** Get fields to export */
237
getFields(): string[];
238
/** Set fields to export */
239
setFields(fields: string[]): void;
240
241
/** Get page number */
242
getPage(): number;
243
/** Set page number */
244
setPage(page: number): void;
245
246
/** Get custom view ID */
247
getCvid(): string;
248
/** Set custom view ID */
249
setCvid(cvid: string): void;
250
}
251
252
/**
253
* Callback configuration for job completion notification
254
*/
255
class CallBack {
256
/** Get callback URL */
257
getUrl(): string;
258
/** Set callback URL */
259
setUrl(url: string): void;
260
261
/** Get HTTP method */
262
getMethod(): string;
263
/** Set HTTP method (post/put) */
264
setMethod(method: string): void;
265
}
266
267
/**
268
* Job details response
269
*/
270
class JobDetail {
271
/** Get job ID */
272
getId(): string;
273
274
/** Get job operation */
275
getOperation(): string;
276
277
/** Get job state */
278
getState(): string;
279
280
/** Get query details */
281
getQuery(): Query;
282
283
/** Get job creation time */
284
getCreatedTime(): Date;
285
286
/** Get job completion time */
287
getCompletedTime(): Date;
288
289
/** Get created by user */
290
getCreatedBy(): User;
291
292
/** Get file type */
293
getFileType(): string;
294
295
/** Get result details */
296
getResult(): Result;
297
}
298
```
299
300
### Bulk Write Data Models
301
302
Data models for configuring bulk write operations.
303
304
```javascript { .api }
305
/**
306
* Request wrapper for bulk write operations
307
*/
308
class RequestWrapper {
309
/** Get character encoding */
310
getCharacterEncoding(): string;
311
/** Set character encoding (UTF-8, ISO-8859-1, etc.) */
312
setCharacterEncoding(characterEncoding: string): void;
313
314
/** Get operation type */
315
getOperation(): string;
316
/** Set operation type (insert, update, upsert) */
317
setOperation(operation: string): void;
318
319
/** Get callback configuration */
320
getCallback(): CallBack;
321
/** Set callback configuration */
322
setCallback(callback: CallBack): void;
323
324
/** Get resource configuration */
325
getResource(): Resource[];
326
/** Set resource configuration */
327
setResource(resource: Resource[]): void;
328
}
329
330
/**
331
* Resource configuration for bulk write
332
*/
333
class Resource {
334
/** Get resource type */
335
getType(): string;
336
/** Set resource type (data, template) */
337
setType(type: string): void;
338
339
/** Get module to import into */
340
getModule(): string;
341
/** Set module to import into */
342
setModule(module: string): void;
343
344
/** Get uploaded file ID */
345
getFileId(): string;
346
/** Set uploaded file ID */
347
setFileId(fileId: string): void;
348
349
/** Get ignore empty flag */
350
getIgnoreEmpty(): boolean;
351
/** Set ignore empty flag */
352
setIgnoreEmpty(ignoreEmpty: boolean): void;
353
354
/** Get field to find duplicates by */
355
getFindBy(): string;
356
/** Set field to find duplicates by (for upsert) */
357
setFindBy(findBy: string): void;
358
359
/** Get field mappings */
360
getFieldMappings(): FieldMapping[];
361
/** Set field mappings */
362
setFieldMappings(fieldMappings: FieldMapping[]): void;
363
}
364
365
/**
366
* Field mapping configuration
367
*/
368
class FieldMapping {
369
/** Get API name of the field */
370
getAPIName(): string;
371
/** Set API name of the field */
372
setAPIName(apiName: string): void;
373
374
/** Get index in the file */
375
getIndex(): number;
376
/** Set index in the file */
377
setIndex(index: number): void;
378
379
/** Get format for date/time fields */
380
getFormat(): string;
381
/** Set format for date/time fields */
382
setFormat(format: string): void;
383
384
/** Get find by flag */
385
getFindBy(): string;
386
/** Set find by flag */
387
setFindBy(findBy: string): void;
388
389
/** Get default value */
390
getDefaultValue(): any;
391
/** Set default value */
392
setDefaultValue(defaultValue: any): void;
393
}
394
395
/**
396
* Bulk write result details
397
*/
398
class Result {
399
/** Get download URL for results */
400
getDownloadUrl(): string;
401
402
/** Get record count */
403
getCount(): number;
404
}
405
```
406
407
### Job Status and Operations
408
409
Constants for job statuses and operation types.
410
411
```javascript { .api }
412
/**
413
* Bulk operation job states
414
*/
415
class JobState {
416
static ADDED: string = "ADDED";
417
static IN_PROGRESS: string = "IN_PROGRESS";
418
static COMPLETED: string = "COMPLETED";
419
static FAILED: string = "FAILED";
420
static PARTIALLY_COMPLETED: string = "PARTIALLY_COMPLETED";
421
}
422
423
/**
424
* Bulk write operation types
425
*/
426
class OperationType {
427
static INSERT: string = "insert";
428
static UPDATE: string = "update";
429
static UPSERT: string = "upsert";
430
}
431
432
/**
433
* Supported file types for bulk operations
434
*/
435
class FileType {
436
static CSV: string = "csv";
437
static ICS: string = "ics"; // For calendar exports
438
static ZIP: string = "zip"; // For results with attachments
439
}
440
```