@trg-admin/n8n-nodes-zoho-desk 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -85,17 +85,25 @@ async function zohoDeskApiRequest(method, endpoint, body = {}, qs = {}, itemInde
|
|
|
85
85
|
async function zohoDeskApiRequestAllItems(method, endpoint, body = {}, qs = {}, itemIndex = 0) {
|
|
86
86
|
const returnData = [];
|
|
87
87
|
let responseData;
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const query = {
|
|
89
|
+
...qs,
|
|
90
|
+
limit: qs.limit || 100,
|
|
91
|
+
from: qs.from || 0,
|
|
92
|
+
};
|
|
90
93
|
do {
|
|
91
|
-
responseData = await zohoDeskApiRequest.call(this, method, endpoint, body,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
responseData = await zohoDeskApiRequest.call(this, method, endpoint, body, query, itemIndex);
|
|
95
|
+
const items = Array.isArray(responseData?.data)
|
|
96
|
+
? responseData.data
|
|
97
|
+
: Array.isArray(responseData)
|
|
98
|
+
? responseData
|
|
99
|
+
: [];
|
|
100
|
+
if (items.length > 0) {
|
|
101
|
+
returnData.push(...items);
|
|
102
|
+
if (items.length < query.limit) {
|
|
95
103
|
// Last page
|
|
96
104
|
break;
|
|
97
105
|
}
|
|
98
|
-
|
|
106
|
+
query.from = query.from + items.length;
|
|
99
107
|
}
|
|
100
108
|
else {
|
|
101
109
|
break;
|
|
@@ -459,13 +459,9 @@ class ZohoDesk {
|
|
|
459
459
|
loadOptions: {
|
|
460
460
|
async getDepartments() {
|
|
461
461
|
try {
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
: Array.isArray(responseData)
|
|
466
|
-
? responseData
|
|
467
|
-
: [];
|
|
468
|
-
return departments.map((department) => {
|
|
462
|
+
const departments = (await GenericFunctions_1.zohoDeskApiRequestAllItems.call(this, 'GET', '/departments', {}, {}, 0));
|
|
463
|
+
return departments
|
|
464
|
+
.map((department) => {
|
|
469
465
|
const name = department.name ||
|
|
470
466
|
department.departmentName ||
|
|
471
467
|
String(department.id);
|
|
@@ -473,7 +469,8 @@ class ZohoDesk {
|
|
|
473
469
|
name,
|
|
474
470
|
value: department.id,
|
|
475
471
|
};
|
|
476
|
-
})
|
|
472
|
+
})
|
|
473
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
477
474
|
}
|
|
478
475
|
catch (error) {
|
|
479
476
|
throw new Error(`Failed to load departments. Error: ${error.message}. Ensure Organization ID is correct and Desk API Base URL matches your region.`);
|
|
@@ -27,7 +27,7 @@ function getDeskBaseUrl(tokenUrl = '', apiDomain = '', overrideBaseUrl = '') {
|
|
|
27
27
|
return 'https://desk.zoho.com.cn';
|
|
28
28
|
return 'https://desk.zoho.com';
|
|
29
29
|
}
|
|
30
|
-
async function deskRequest(context, method, endpoint, organizationId, body = {}) {
|
|
30
|
+
async function deskRequest(context, method, endpoint, organizationId, body = {}, qs = {}) {
|
|
31
31
|
const credentials = (await context.getCredentials('zohoCRMDeskOAuth2Api'));
|
|
32
32
|
const { oauthTokenData, accessTokenUrl, authUrl, deskBaseUrl } = credentials;
|
|
33
33
|
const baseUrl = getDeskBaseUrl(accessTokenUrl || authUrl || '', oauthTokenData?.api_domain || '', deskBaseUrl || '');
|
|
@@ -40,6 +40,9 @@ async function deskRequest(context, method, endpoint, organizationId, body = {})
|
|
|
40
40
|
},
|
|
41
41
|
json: true,
|
|
42
42
|
};
|
|
43
|
+
if (Object.keys(qs).length) {
|
|
44
|
+
options.qs = qs;
|
|
45
|
+
}
|
|
43
46
|
if (method !== 'GET' && method !== 'DELETE' && Object.keys(body).length) {
|
|
44
47
|
options.body = body;
|
|
45
48
|
}
|
|
@@ -50,6 +53,34 @@ async function deskRequest(context, method, endpoint, organizationId, body = {})
|
|
|
50
53
|
throw new n8n_workflow_1.NodeApiError(context.getNode(), error);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
56
|
+
async function deskRequestAllItems(context, method, endpoint, organizationId, body = {}, qs = {}) {
|
|
57
|
+
const returnData = [];
|
|
58
|
+
let responseData;
|
|
59
|
+
const query = {
|
|
60
|
+
...qs,
|
|
61
|
+
limit: qs.limit || 100,
|
|
62
|
+
from: qs.from || 0,
|
|
63
|
+
};
|
|
64
|
+
do {
|
|
65
|
+
responseData = await deskRequest(context, method, endpoint, organizationId, body, query);
|
|
66
|
+
const items = Array.isArray(responseData?.data)
|
|
67
|
+
? responseData.data
|
|
68
|
+
: Array.isArray(responseData)
|
|
69
|
+
? responseData
|
|
70
|
+
: [];
|
|
71
|
+
if (items.length > 0) {
|
|
72
|
+
returnData.push(...items);
|
|
73
|
+
if (items.length < query.limit) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
query.from = query.from + items.length;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
} while (true);
|
|
82
|
+
return returnData;
|
|
83
|
+
}
|
|
53
84
|
async function deskWebhookRequest(context, method, endpoint, body = {}) {
|
|
54
85
|
const organizationId = context.getNodeParameter('organizationId');
|
|
55
86
|
return deskRequest(context, method, endpoint, organizationId, body);
|
|
@@ -208,16 +239,13 @@ class ZohoDeskTrigger {
|
|
|
208
239
|
async getDepartments() {
|
|
209
240
|
const organizationId = this.getNodeParameter('organizationId', 0, '');
|
|
210
241
|
try {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
: Array.isArray(responseData)
|
|
215
|
-
? responseData
|
|
216
|
-
: [];
|
|
217
|
-
return departments.map((dept) => ({
|
|
242
|
+
const departments = await deskRequestAllItems(this, 'GET', '/departments', organizationId);
|
|
243
|
+
return departments
|
|
244
|
+
.map((dept) => ({
|
|
218
245
|
name: dept.name || dept.departmentName || String(dept.id),
|
|
219
246
|
value: dept.id,
|
|
220
|
-
}))
|
|
247
|
+
}))
|
|
248
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
221
249
|
}
|
|
222
250
|
catch (error) {
|
|
223
251
|
throw new Error(`Failed to load departments: ${error.message}. Ensure Organization ID is set correctly.`);
|