n8n-nodes-perfexcrm 0.1.8 → 0.1.10

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.
@@ -20,8 +20,8 @@ class PerfexCrm {
20
20
  defaults: {
21
21
  name: 'PerfexCRM',
22
22
  },
23
- inputs: ["main" /* NodeConnectionType.Main */],
24
- outputs: ["main" /* NodeConnectionType.Main */],
23
+ inputs: ['main'],
24
+ outputs: ['main'],
25
25
  credentials: [
26
26
  {
27
27
  name: 'perfexCrmApi',
@@ -86,6 +86,11 @@ class PerfexCrm {
86
86
  let responseData;
87
87
  const baseUrl = credentials.baseUrl;
88
88
  const apiVersion = credentials.apiVersion;
89
+ const apiKey = credentials.apiKey;
90
+ // Headers with API key for authentication
91
+ const headers = {
92
+ 'X-API-KEY': apiKey,
93
+ };
89
94
  for (let i = 0; i < items.length; i++) {
90
95
  try {
91
96
  if (resource === 'customer') {
@@ -101,6 +106,7 @@ class PerfexCrm {
101
106
  url: `${baseUrl}/api/${apiVersion}/customers`,
102
107
  body,
103
108
  json: true,
109
+ headers,
104
110
  });
105
111
  }
106
112
  else if (operation === 'get') {
@@ -109,6 +115,7 @@ class PerfexCrm {
109
115
  method: 'GET',
110
116
  url: `${baseUrl}/api/${apiVersion}/customers/${customerId}`,
111
117
  json: true,
118
+ headers,
112
119
  });
113
120
  }
114
121
  else if (operation === 'getAll') {
@@ -127,6 +134,7 @@ class PerfexCrm {
127
134
  url: `${baseUrl}/api/${apiVersion}/customers`,
128
135
  qs,
129
136
  json: true,
137
+ headers,
130
138
  });
131
139
  if (responseData.data) {
132
140
  responseData = responseData.data;
@@ -141,6 +149,7 @@ class PerfexCrm {
141
149
  url: `${baseUrl}/api/${apiVersion}/customers/${customerId}`,
142
150
  body,
143
151
  json: true,
152
+ headers,
144
153
  });
145
154
  }
146
155
  else if (operation === 'delete') {
@@ -149,8 +158,69 @@ class PerfexCrm {
149
158
  method: 'DELETE',
150
159
  url: `${baseUrl}/api/${apiVersion}/customers/${customerId}`,
151
160
  json: true,
161
+ headers,
152
162
  });
153
163
  }
164
+ else if (operation === 'getContacts') {
165
+ const customerId = this.getNodeParameter('customerId', i);
166
+ responseData = await this.helpers.request({
167
+ method: 'GET',
168
+ url: `${baseUrl}/api/${apiVersion}/customers/${customerId}/contacts`,
169
+ json: true,
170
+ headers,
171
+ });
172
+ if (responseData.data) {
173
+ responseData = responseData.data;
174
+ }
175
+ }
176
+ else if (operation === 'getContracts') {
177
+ const customerId = this.getNodeParameter('customerId', i);
178
+ responseData = await this.helpers.request({
179
+ method: 'GET',
180
+ url: `${baseUrl}/api/${apiVersion}/customers/${customerId}/contracts`,
181
+ json: true,
182
+ headers,
183
+ });
184
+ if (responseData.data) {
185
+ responseData = responseData.data;
186
+ }
187
+ }
188
+ else if (operation === 'getInvoices') {
189
+ const customerId = this.getNodeParameter('customerId', i);
190
+ responseData = await this.helpers.request({
191
+ method: 'GET',
192
+ url: `${baseUrl}/api/${apiVersion}/customers/${customerId}/invoices`,
193
+ json: true,
194
+ headers,
195
+ });
196
+ if (responseData.data) {
197
+ responseData = responseData.data;
198
+ }
199
+ }
200
+ else if (operation === 'getProjects') {
201
+ const customerId = this.getNodeParameter('customerId', i);
202
+ responseData = await this.helpers.request({
203
+ method: 'GET',
204
+ url: `${baseUrl}/api/${apiVersion}/customers/${customerId}/projects`,
205
+ json: true,
206
+ headers,
207
+ });
208
+ if (responseData.data) {
209
+ responseData = responseData.data;
210
+ }
211
+ }
212
+ else if (operation === 'getTickets') {
213
+ const customerId = this.getNodeParameter('customerId', i);
214
+ responseData = await this.helpers.request({
215
+ method: 'GET',
216
+ url: `${baseUrl}/api/${apiVersion}/customers/${customerId}/tickets`,
217
+ json: true,
218
+ headers,
219
+ });
220
+ if (responseData.data) {
221
+ responseData = responseData.data;
222
+ }
223
+ }
154
224
  }
155
225
  else if (resource === 'ticket') {
156
226
  if (operation === 'create') {
@@ -167,6 +237,7 @@ class PerfexCrm {
167
237
  url: `${baseUrl}/api/${apiVersion}/tickets`,
168
238
  body,
169
239
  json: true,
240
+ headers,
170
241
  });
171
242
  }
172
243
  else if (operation === 'get') {
@@ -181,6 +252,7 @@ class PerfexCrm {
181
252
  url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}`,
182
253
  qs,
183
254
  json: true,
255
+ headers,
184
256
  });
185
257
  }
186
258
  else if (operation === 'getAll') {
@@ -208,6 +280,7 @@ class PerfexCrm {
208
280
  url: `${baseUrl}/api/${apiVersion}/tickets`,
209
281
  qs,
210
282
  json: true,
283
+ headers,
211
284
  });
212
285
  if (responseData.data) {
213
286
  responseData = responseData.data;
@@ -222,6 +295,7 @@ class PerfexCrm {
222
295
  url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}`,
223
296
  body,
224
297
  json: true,
298
+ headers,
225
299
  });
226
300
  }
227
301
  else if (operation === 'delete') {
@@ -230,6 +304,7 @@ class PerfexCrm {
230
304
  method: 'DELETE',
231
305
  url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}`,
232
306
  json: true,
307
+ headers,
233
308
  });
234
309
  }
235
310
  else if (operation === 'addReply') {
@@ -245,8 +320,53 @@ class PerfexCrm {
245
320
  url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}/replies`,
246
321
  body,
247
322
  json: true,
323
+ headers,
324
+ });
325
+ }
326
+ else if (operation === 'getReply') {
327
+ const ticketId = this.getNodeParameter('ticketId', i);
328
+ const replyId = this.getNodeParameter('replyId', i);
329
+ responseData = await this.helpers.request({
330
+ method: 'GET',
331
+ url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}/replies/${replyId}`,
332
+ json: true,
333
+ headers,
248
334
  });
249
335
  }
336
+ else if (operation === 'updateReply') {
337
+ const ticketId = this.getNodeParameter('ticketId', i);
338
+ const replyId = this.getNodeParameter('replyId', i);
339
+ const updateFields = this.getNodeParameter('updateFields', i);
340
+ responseData = await this.helpers.request({
341
+ method: 'PUT',
342
+ url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}/replies/${replyId}`,
343
+ body: updateFields,
344
+ json: true,
345
+ headers,
346
+ });
347
+ }
348
+ else if (operation === 'deleteReply') {
349
+ const ticketId = this.getNodeParameter('ticketId', i);
350
+ const replyId = this.getNodeParameter('replyId', i);
351
+ responseData = await this.helpers.request({
352
+ method: 'DELETE',
353
+ url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}/replies/${replyId}`,
354
+ json: true,
355
+ headers,
356
+ });
357
+ }
358
+ else if (operation === 'listReplies') {
359
+ const ticketId = this.getNodeParameter('ticketId', i);
360
+ responseData = await this.helpers.request({
361
+ method: 'GET',
362
+ url: `${baseUrl}/api/${apiVersion}/tickets/${ticketId}/replies`,
363
+ json: true,
364
+ headers,
365
+ });
366
+ if (responseData.data) {
367
+ responseData = responseData.data;
368
+ }
369
+ }
250
370
  }
251
371
  else if (resource === 'invoice') {
252
372
  if (operation === 'create') {
@@ -267,6 +387,7 @@ class PerfexCrm {
267
387
  url: `${baseUrl}/api/${apiVersion}/invoices`,
268
388
  body,
269
389
  json: true,
390
+ headers,
270
391
  });
271
392
  }
272
393
  else if (operation === 'get') {
@@ -275,6 +396,7 @@ class PerfexCrm {
275
396
  method: 'GET',
276
397
  url: `${baseUrl}/api/${apiVersion}/invoices/${invoiceId}`,
277
398
  json: true,
399
+ headers,
278
400
  });
279
401
  }
280
402
  else if (operation === 'getAll') {
@@ -293,11 +415,33 @@ class PerfexCrm {
293
415
  url: `${baseUrl}/api/${apiVersion}/invoices`,
294
416
  qs,
295
417
  json: true,
418
+ headers,
296
419
  });
297
420
  if (responseData.data) {
298
421
  responseData = responseData.data;
299
422
  }
300
423
  }
424
+ else if (operation === 'update') {
425
+ const invoiceId = this.getNodeParameter('invoiceId', i);
426
+ const updateFields = this.getNodeParameter('updateFields', i);
427
+ const body = updateFields;
428
+ responseData = await this.helpers.request({
429
+ method: 'PUT',
430
+ url: `${baseUrl}/api/${apiVersion}/invoices/${invoiceId}`,
431
+ body,
432
+ json: true,
433
+ headers,
434
+ });
435
+ }
436
+ else if (operation === 'delete') {
437
+ const invoiceId = this.getNodeParameter('invoiceId', i);
438
+ responseData = await this.helpers.request({
439
+ method: 'DELETE',
440
+ url: `${baseUrl}/api/${apiVersion}/invoices/${invoiceId}`,
441
+ json: true,
442
+ headers,
443
+ });
444
+ }
301
445
  }
302
446
  else if (resource === 'lead') {
303
447
  if (operation === 'create') {
@@ -312,6 +456,7 @@ class PerfexCrm {
312
456
  url: `${baseUrl}/api/${apiVersion}/leads`,
313
457
  body,
314
458
  json: true,
459
+ headers,
315
460
  });
316
461
  }
317
462
  else if (operation === 'get') {
@@ -320,6 +465,50 @@ class PerfexCrm {
320
465
  method: 'GET',
321
466
  url: `${baseUrl}/api/${apiVersion}/leads/${leadId}`,
322
467
  json: true,
468
+ headers,
469
+ });
470
+ }
471
+ else if (operation === 'getAll') {
472
+ const returnAll = this.getNodeParameter('returnAll', i);
473
+ const filters = this.getNodeParameter('filters', i);
474
+ const qs = {};
475
+ if (!returnAll) {
476
+ qs.limit = this.getNodeParameter('limit', i);
477
+ }
478
+ else {
479
+ qs.limit = 1000;
480
+ }
481
+ Object.assign(qs, filters);
482
+ responseData = await this.helpers.request({
483
+ method: 'GET',
484
+ url: `${baseUrl}/api/${apiVersion}/leads`,
485
+ qs,
486
+ json: true,
487
+ headers,
488
+ });
489
+ if (responseData.data) {
490
+ responseData = responseData.data;
491
+ }
492
+ }
493
+ else if (operation === 'update') {
494
+ const leadId = this.getNodeParameter('leadId', i);
495
+ const updateFields = this.getNodeParameter('updateFields', i);
496
+ const body = updateFields;
497
+ responseData = await this.helpers.request({
498
+ method: 'PUT',
499
+ url: `${baseUrl}/api/${apiVersion}/leads/${leadId}`,
500
+ body,
501
+ json: true,
502
+ headers,
503
+ });
504
+ }
505
+ else if (operation === 'delete') {
506
+ const leadId = this.getNodeParameter('leadId', i);
507
+ responseData = await this.helpers.request({
508
+ method: 'DELETE',
509
+ url: `${baseUrl}/api/${apiVersion}/leads/${leadId}`,
510
+ json: true,
511
+ headers,
323
512
  });
324
513
  }
325
514
  else if (operation === 'convert') {
@@ -328,6 +517,7 @@ class PerfexCrm {
328
517
  method: 'POST',
329
518
  url: `${baseUrl}/api/${apiVersion}/leads/${leadId}/convert`,
330
519
  json: true,
520
+ headers,
331
521
  });
332
522
  }
333
523
  }
@@ -346,6 +536,7 @@ class PerfexCrm {
346
536
  url: `${baseUrl}/api/${apiVersion}/projects`,
347
537
  body,
348
538
  json: true,
539
+ headers,
349
540
  });
350
541
  }
351
542
  else if (operation === 'get') {
@@ -354,6 +545,50 @@ class PerfexCrm {
354
545
  method: 'GET',
355
546
  url: `${baseUrl}/api/${apiVersion}/projects/${projectId}`,
356
547
  json: true,
548
+ headers,
549
+ });
550
+ }
551
+ else if (operation === 'getAll') {
552
+ const returnAll = this.getNodeParameter('returnAll', i);
553
+ const filters = this.getNodeParameter('filters', i);
554
+ const qs = {};
555
+ if (!returnAll) {
556
+ qs.limit = this.getNodeParameter('limit', i);
557
+ }
558
+ else {
559
+ qs.limit = 1000;
560
+ }
561
+ Object.assign(qs, filters);
562
+ responseData = await this.helpers.request({
563
+ method: 'GET',
564
+ url: `${baseUrl}/api/${apiVersion}/projects`,
565
+ qs,
566
+ json: true,
567
+ headers,
568
+ });
569
+ if (responseData.data) {
570
+ responseData = responseData.data;
571
+ }
572
+ }
573
+ else if (operation === 'update') {
574
+ const projectId = this.getNodeParameter('projectId', i);
575
+ const updateFields = this.getNodeParameter('updateFields', i);
576
+ const body = updateFields;
577
+ responseData = await this.helpers.request({
578
+ method: 'PUT',
579
+ url: `${baseUrl}/api/${apiVersion}/projects/${projectId}`,
580
+ body,
581
+ json: true,
582
+ headers,
583
+ });
584
+ }
585
+ else if (operation === 'delete') {
586
+ const projectId = this.getNodeParameter('projectId', i);
587
+ responseData = await this.helpers.request({
588
+ method: 'DELETE',
589
+ url: `${baseUrl}/api/${apiVersion}/projects/${projectId}`,
590
+ json: true,
591
+ headers,
357
592
  });
358
593
  }
359
594
  }
@@ -376,6 +611,7 @@ class PerfexCrm {
376
611
  url: `${baseUrl}/api/${apiVersion}/contracts`,
377
612
  body,
378
613
  json: true,
614
+ headers,
379
615
  });
380
616
  }
381
617
  else if (operation === 'get') {
@@ -384,6 +620,66 @@ class PerfexCrm {
384
620
  method: 'GET',
385
621
  url: `${baseUrl}/api/${apiVersion}/contracts/${contractId}`,
386
622
  json: true,
623
+ headers,
624
+ });
625
+ }
626
+ else if (operation === 'getAll') {
627
+ const returnAll = this.getNodeParameter('returnAll', i);
628
+ const filters = this.getNodeParameter('filters', i);
629
+ const qs = {};
630
+ if (!returnAll) {
631
+ qs.limit = this.getNodeParameter('limit', i);
632
+ }
633
+ else {
634
+ qs.limit = 1000;
635
+ }
636
+ Object.assign(qs, filters);
637
+ responseData = await this.helpers.request({
638
+ method: 'GET',
639
+ url: `${baseUrl}/api/${apiVersion}/contracts`,
640
+ qs,
641
+ json: true,
642
+ headers,
643
+ });
644
+ if (responseData.data) {
645
+ responseData = responseData.data;
646
+ }
647
+ }
648
+ else if (operation === 'update') {
649
+ const contractId = this.getNodeParameter('contractId', i);
650
+ const updateFields = this.getNodeParameter('updateFields', i);
651
+ const body = updateFields;
652
+ responseData = await this.helpers.request({
653
+ method: 'PUT',
654
+ url: `${baseUrl}/api/${apiVersion}/contracts/${contractId}`,
655
+ body,
656
+ json: true,
657
+ headers,
658
+ });
659
+ }
660
+ else if (operation === 'delete') {
661
+ const contractId = this.getNodeParameter('contractId', i);
662
+ responseData = await this.helpers.request({
663
+ method: 'DELETE',
664
+ url: `${baseUrl}/api/${apiVersion}/contracts/${contractId}`,
665
+ json: true,
666
+ headers,
667
+ });
668
+ }
669
+ else if (operation === 'sign') {
670
+ const contractId = this.getNodeParameter('contractId', i);
671
+ const signature = this.getNodeParameter('signature', i);
672
+ const additionalFields = this.getNodeParameter('additionalFields', i);
673
+ const body = {
674
+ signature,
675
+ ...additionalFields,
676
+ };
677
+ responseData = await this.helpers.request({
678
+ method: 'POST',
679
+ url: `${baseUrl}/api/${apiVersion}/contracts/${contractId}/sign`,
680
+ body,
681
+ json: true,
682
+ headers,
387
683
  });
388
684
  }
389
685
  }
@@ -15,7 +15,7 @@ class PerfexCrmTrigger {
15
15
  name: 'PerfexCRM Trigger',
16
16
  },
17
17
  inputs: [],
18
- outputs: ["main" /* NodeConnectionType.Main */],
18
+ outputs: ['main'],
19
19
  credentials: [
20
20
  {
21
21
  name: 'perfexCrmApi',
@@ -307,6 +307,10 @@ class PerfexCrmTrigger {
307
307
  const credentials = await this.getCredentials('perfexCrmApi');
308
308
  const baseUrl = credentials.baseUrl;
309
309
  const apiVersion = credentials.apiVersion;
310
+ const apiKey = credentials.apiKey;
311
+ const headers = {
312
+ 'X-API-KEY': apiKey,
313
+ };
310
314
  // Check if webhook exists
311
315
  if (webhookData.webhookId) {
312
316
  try {
@@ -314,6 +318,7 @@ class PerfexCrmTrigger {
314
318
  method: 'GET',
315
319
  url: `${baseUrl}/api/${apiVersion}/webhooks/${webhookData.webhookId}`,
316
320
  json: true,
321
+ headers,
317
322
  });
318
323
  if (response && response.data) {
319
324
  return true;
@@ -333,6 +338,10 @@ class PerfexCrmTrigger {
333
338
  const credentials = await this.getCredentials('perfexCrmApi');
334
339
  const baseUrl = credentials.baseUrl;
335
340
  const apiVersion = credentials.apiVersion;
341
+ const apiKey = credentials.apiKey;
342
+ const headers = {
343
+ 'X-API-KEY': apiKey,
344
+ };
336
345
  const body = {
337
346
  name: `n8n-webhook-${this.getWorkflow().id}`,
338
347
  url: webhookUrl,
@@ -345,6 +354,7 @@ class PerfexCrmTrigger {
345
354
  url: `${baseUrl}/api/${apiVersion}/webhooks`,
346
355
  body,
347
356
  json: true,
357
+ headers,
348
358
  });
349
359
  if (response.data && response.data.id) {
350
360
  webhookData.webhookId = response.data.id;
@@ -358,11 +368,16 @@ class PerfexCrmTrigger {
358
368
  if (webhookData.webhookId) {
359
369
  const baseUrl = credentials.baseUrl;
360
370
  const apiVersion = credentials.apiVersion;
371
+ const apiKey = credentials.apiKey;
372
+ const headers = {
373
+ 'X-API-KEY': apiKey,
374
+ };
361
375
  try {
362
376
  await this.helpers.request({
363
377
  method: 'DELETE',
364
378
  url: `${baseUrl}/api/${apiVersion}/webhooks/${webhookData.webhookId}`,
365
379
  json: true,
380
+ headers,
366
381
  });
367
382
  }
368
383
  catch (error) {