@trg-admin/n8n-nodes-zoho-desk 0.1.15 → 0.1.16
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.
|
@@ -4,3 +4,7 @@ export declare function zohoDeskApiRequest(this: IExecuteFunctions | ILoadOption
|
|
|
4
4
|
* Make an API request to paginate through all items
|
|
5
5
|
*/
|
|
6
6
|
export declare function zohoDeskApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, endpoint: string, body?: IDataObject, qs?: IDataObject, itemIndex?: number): Promise<any>;
|
|
7
|
+
/**
|
|
8
|
+
* Helper to look up a contact by email address in Zoho Desk
|
|
9
|
+
*/
|
|
10
|
+
export declare function getContactByEmail(this: IExecuteFunctions | ILoadOptionsFunctions, email: string, itemIndex?: number): Promise<IDataObject>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zohoDeskApiRequest = zohoDeskApiRequest;
|
|
4
4
|
exports.zohoDeskApiRequestAllItems = zohoDeskApiRequestAllItems;
|
|
5
|
+
exports.getContactByEmail = getContactByEmail;
|
|
5
6
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
6
7
|
function getDeskBaseUrl(tokenUrl = '', apiDomain = '', overrideBaseUrl = '') {
|
|
7
8
|
if (overrideBaseUrl) {
|
|
@@ -102,3 +103,23 @@ async function zohoDeskApiRequestAllItems(method, endpoint, body = {}, qs = {},
|
|
|
102
103
|
} while (true);
|
|
103
104
|
return returnData;
|
|
104
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Helper to look up a contact by email address in Zoho Desk
|
|
108
|
+
*/
|
|
109
|
+
async function getContactByEmail(email, itemIndex = 0) {
|
|
110
|
+
const trimmedEmail = email.trim();
|
|
111
|
+
if (!trimmedEmail) {
|
|
112
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), new Error('Contact Email cannot be empty'), { itemIndex });
|
|
113
|
+
}
|
|
114
|
+
const responseData = await zohoDeskApiRequest.call(this, 'GET', '/contacts/search', {}, { email: trimmedEmail, searchStr: trimmedEmail }, itemIndex);
|
|
115
|
+
const contacts = Array.isArray(responseData.data)
|
|
116
|
+
? responseData.data
|
|
117
|
+
: Array.isArray(responseData)
|
|
118
|
+
? responseData
|
|
119
|
+
: [];
|
|
120
|
+
if (contacts.length === 0) {
|
|
121
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), new Error(`No contact found with email "${trimmedEmail}" in Zoho Desk`), { itemIndex });
|
|
122
|
+
}
|
|
123
|
+
const exactMatch = contacts.find((c) => String(c.email || '').toLowerCase() === trimmedEmail.toLowerCase());
|
|
124
|
+
return exactMatch || contacts[0];
|
|
125
|
+
}
|
|
@@ -159,7 +159,7 @@ class ZohoDesk {
|
|
|
159
159
|
name: 'contactId',
|
|
160
160
|
type: 'string',
|
|
161
161
|
default: '',
|
|
162
|
-
description: 'ID of existing contact (
|
|
162
|
+
description: 'ID of existing contact (or enter email address)',
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
165
|
displayName: 'Task ID',
|
|
@@ -248,14 +248,61 @@ class ZohoDesk {
|
|
|
248
248
|
description: 'Whether to return all results or limit to specified number',
|
|
249
249
|
},
|
|
250
250
|
// ================== Contact Resource Parameters ==================
|
|
251
|
+
{
|
|
252
|
+
displayName: 'By',
|
|
253
|
+
name: 'by',
|
|
254
|
+
type: 'options',
|
|
255
|
+
options: [
|
|
256
|
+
{
|
|
257
|
+
name: 'Contact ID',
|
|
258
|
+
value: 'id',
|
|
259
|
+
description: 'Identify contact by Zoho Desk Contact ID',
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'Email',
|
|
263
|
+
value: 'email',
|
|
264
|
+
description: 'Identify contact by Email Address',
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
default: 'id',
|
|
268
|
+
displayOptions: {
|
|
269
|
+
show: {
|
|
270
|
+
resource: ['contact'],
|
|
271
|
+
operation: ['get', 'update'],
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
description: 'How to identify the contact',
|
|
275
|
+
},
|
|
251
276
|
{
|
|
252
277
|
displayName: 'Contact ID',
|
|
253
278
|
name: 'contactId',
|
|
254
279
|
type: 'string',
|
|
255
280
|
default: '',
|
|
256
281
|
required: true,
|
|
257
|
-
displayOptions: {
|
|
258
|
-
|
|
282
|
+
displayOptions: {
|
|
283
|
+
show: {
|
|
284
|
+
resource: ['contact'],
|
|
285
|
+
operation: ['get', 'update'],
|
|
286
|
+
by: ['id'],
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
description: 'The unique ID of the contact. You can also enter an email address here.',
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
displayName: 'Contact Email',
|
|
293
|
+
name: 'contactEmail',
|
|
294
|
+
type: 'string',
|
|
295
|
+
placeholder: 'e.g. name@example.com',
|
|
296
|
+
default: '',
|
|
297
|
+
required: true,
|
|
298
|
+
displayOptions: {
|
|
299
|
+
show: {
|
|
300
|
+
resource: ['contact'],
|
|
301
|
+
operation: ['get', 'update'],
|
|
302
|
+
by: ['email'],
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
description: 'Email address of the contact',
|
|
259
306
|
},
|
|
260
307
|
{
|
|
261
308
|
displayName: 'Last Name',
|
|
@@ -526,6 +573,10 @@ class ZohoDesk {
|
|
|
526
573
|
if (description) {
|
|
527
574
|
body.description = description;
|
|
528
575
|
}
|
|
576
|
+
if (body.contactId && typeof body.contactId === 'string' && body.contactId.includes('@')) {
|
|
577
|
+
const contact = await GenericFunctions_1.getContactByEmail.call(this, body.contactId, i);
|
|
578
|
+
body.contactId = contact.id;
|
|
579
|
+
}
|
|
529
580
|
const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'POST', '/tickets', body, {}, i);
|
|
530
581
|
returnData.push({ json: responseData });
|
|
531
582
|
}
|
|
@@ -552,6 +603,10 @@ class ZohoDesk {
|
|
|
552
603
|
if (description) {
|
|
553
604
|
body.description = description;
|
|
554
605
|
}
|
|
606
|
+
if (body.contactId && typeof body.contactId === 'string' && body.contactId.includes('@')) {
|
|
607
|
+
const contact = await GenericFunctions_1.getContactByEmail.call(this, body.contactId, i);
|
|
608
|
+
body.contactId = contact.id;
|
|
609
|
+
}
|
|
555
610
|
const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'PATCH', `/tickets/${ticketId}`, body, {}, i);
|
|
556
611
|
returnData.push({ json: responseData });
|
|
557
612
|
}
|
|
@@ -559,8 +614,25 @@ class ZohoDesk {
|
|
|
559
614
|
// ==================== CONTACT OPERATIONS ====================
|
|
560
615
|
if (resource === 'contact') {
|
|
561
616
|
if (operation === 'get') {
|
|
562
|
-
const
|
|
563
|
-
|
|
617
|
+
const by = this.getNodeParameter('by', i, 'id');
|
|
618
|
+
let identifier = '';
|
|
619
|
+
let isEmail = by === 'email';
|
|
620
|
+
if (by === 'email') {
|
|
621
|
+
identifier = this.getNodeParameter('contactEmail', i);
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
identifier = this.getNodeParameter('contactId', i);
|
|
625
|
+
if (identifier.includes('@')) {
|
|
626
|
+
isEmail = true;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
let responseData;
|
|
630
|
+
if (isEmail) {
|
|
631
|
+
responseData = await GenericFunctions_1.getContactByEmail.call(this, identifier, i);
|
|
632
|
+
}
|
|
633
|
+
else {
|
|
634
|
+
responseData = (await GenericFunctions_1.zohoDeskApiRequest.call(this, 'GET', `/contacts/${identifier}`, {}, {}, i));
|
|
635
|
+
}
|
|
564
636
|
returnData.push({ json: responseData });
|
|
565
637
|
}
|
|
566
638
|
if (operation === 'getAll') {
|
|
@@ -595,9 +667,25 @@ class ZohoDesk {
|
|
|
595
667
|
returnData.push({ json: responseData });
|
|
596
668
|
}
|
|
597
669
|
if (operation === 'update') {
|
|
598
|
-
const
|
|
670
|
+
const by = this.getNodeParameter('by', i, 'id');
|
|
671
|
+
let identifier = '';
|
|
672
|
+
let isEmail = by === 'email';
|
|
673
|
+
if (by === 'email') {
|
|
674
|
+
identifier = this.getNodeParameter('contactEmail', i);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
identifier = this.getNodeParameter('contactId', i);
|
|
678
|
+
if (identifier.includes('@')) {
|
|
679
|
+
isEmail = true;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
let targetContactId = identifier;
|
|
683
|
+
if (isEmail) {
|
|
684
|
+
const contact = await GenericFunctions_1.getContactByEmail.call(this, identifier, i);
|
|
685
|
+
targetContactId = contact.id;
|
|
686
|
+
}
|
|
599
687
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
600
|
-
const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'PATCH', `/contacts/${
|
|
688
|
+
const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'PATCH', `/contacts/${targetContactId}`, additionalFields, {}, i);
|
|
601
689
|
returnData.push({ json: responseData });
|
|
602
690
|
}
|
|
603
691
|
if (operation === 'search') {
|