@friggframework/api-module-hubspot 1.2.0-canary.293.5731c31.0 → 2.0.0-next.0

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.
package/api.js CHANGED
@@ -1,4 +1,4 @@
1
- const { OAuth2Requester, get } = require('@friggframework/core');
1
+ const {OAuth2Requester, get} = require('@friggframework/core');
2
2
 
3
3
  class Api extends OAuth2Requester {
4
4
  constructor(params) {
@@ -26,8 +26,16 @@ class Api extends OAuth2Requester {
26
26
  deals: '/crm/v3/objects/deals',
27
27
  dealById: (dealId) => `/crm/v3/objects/deals/${dealId}`,
28
28
  searchDeals: '/crm/v3/objects/deals/search',
29
- getBatchAssociations: (fromObject, toObject) =>
30
- `/crm/v3/associations/${fromObject}/${toObject}/batch/read`,
29
+ readBatchAssociations: (fromObjectType, toObjectType) =>
30
+ `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/read`,
31
+ createBatchAssociations: (fromObjectType, toObjectType) =>
32
+ `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/create`,
33
+ createBatchAssociationsDefault: (fromObjectType, toObjectType) =>
34
+ `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/associate/default`,
35
+ deleteBatchAssociations: (fromObjectType, toObjectType) =>
36
+ `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/archive`,
37
+ deleteBatchAssociationLabels: (fromObjectType, toObjectType) =>
38
+ `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/labels/archive`,
31
39
  v1DealInfo: (dealId) => `/deals/v1/deal/${dealId}`,
32
40
  getPipelineDetails: (objType) => `/crm/v3/pipelines/${objType}`,
33
41
  getOwnerById: (ownerId) => `/owners/v2/owners/${ownerId}`,
@@ -56,6 +64,13 @@ class Api extends OAuth2Requester {
56
64
  blogPostById: (blogPostId) => `/cms/v3/blogs/posts/${blogPostId}`,
57
65
  emailTemplates: '/content/api/v2/templates',
58
66
  emailTemplateById: (templateId) => `/content/api/v2/templates/${templateId}`,
67
+ lists: '/crm/v3/lists',
68
+ listById: (listId) => `/crm/v3/lists/${listId}`,
69
+ listSearch: '/crm/v3/lists/search',
70
+ listMemberships: (listId) => `/crm/v3/lists/${listId}/memberships`,
71
+ listMembershipsAddRemove: (listId) => `/crm/v3/lists/${listId}/memberships/add-and-remove`,
72
+ associations: (fromObject, toObject) => `/crm/v4/associations/${fromObject}/${toObject}`,
73
+ associationLabels: (fromObject, toObject) => `/crm/v4/associations/${fromObject}/${toObject}/labels`,
59
74
 
60
75
  };
61
76
 
@@ -67,10 +82,36 @@ class Api extends OAuth2Requester {
67
82
  this.access_token = get(params, 'access_token', null);
68
83
  this.refresh_token = get(params, 'refresh_token', null);
69
84
  }
85
+
70
86
  getAuthUri() {
71
87
  return this.authorizationUri;
72
88
  }
73
89
 
90
+ addJsonHeaders(options) {
91
+ const jsonHeaders = {
92
+ 'Content-Type': 'application/json',
93
+ Accept: 'application/json',
94
+ };
95
+ options.headers = {
96
+ ...jsonHeaders,
97
+ ...options.headers,
98
+ }
99
+ }
100
+ async _post(options, stringify) {
101
+ this.addJsonHeaders(options);
102
+ return super._post(options, stringify);
103
+ }
104
+
105
+ async _patch(options, stringify) {
106
+ this.addJsonHeaders(options);
107
+ return super._patch(options, stringify);
108
+ }
109
+
110
+ async _put(options, stringify) {
111
+ this.addJsonHeaders(options);
112
+ return super._put(options, stringify);
113
+ }
114
+
74
115
  // ************************** Companies **********************************
75
116
 
76
117
  async createCompany(body) {
@@ -79,10 +120,6 @@ class Api extends OAuth2Requester {
79
120
  body: {
80
121
  properties: body,
81
122
  },
82
- headers: {
83
- 'Content-Type': 'application/json',
84
- Accept: 'application/json',
85
- },
86
123
  };
87
124
 
88
125
  return this._post(options);
@@ -100,10 +137,6 @@ class Api extends OAuth2Requester {
100
137
  const options = {
101
138
  url: this.baseUrl + this.URLs.companyById(id),
102
139
  body,
103
- headers: {
104
- 'Content-Type': 'application/json',
105
- Accept: 'application/json',
106
- },
107
140
  };
108
141
  return this._patch(options);
109
142
  }
@@ -112,10 +145,6 @@ class Api extends OAuth2Requester {
112
145
  const options = {
113
146
  url: this.baseUrl + this.URLs.companySearch,
114
147
  body,
115
- headers: {
116
- 'Content-Type': 'application/json',
117
- Accept: 'application/json',
118
- },
119
148
  };
120
149
  return this._post(options);
121
150
  }
@@ -155,10 +184,6 @@ class Api extends OAuth2Requester {
155
184
  const options = {
156
185
  url: this.baseUrl + this.URLs.getBatchCompaniesById,
157
186
  body,
158
- headers: {
159
- 'content-type': 'application/json',
160
- accept: 'application/json',
161
- },
162
187
  query: {
163
188
  archived: 'false',
164
189
  },
@@ -174,10 +199,6 @@ class Api extends OAuth2Requester {
174
199
  body: {
175
200
  properties: body,
176
201
  },
177
- headers: {
178
- 'Content-Type': 'application/json',
179
- Accept: 'application/json',
180
- },
181
202
  };
182
203
 
183
204
  return this._post(options);
@@ -231,10 +252,6 @@ class Api extends OAuth2Requester {
231
252
  body: {
232
253
  properties,
233
254
  },
234
- headers: {
235
- 'Content-Type': 'application/json',
236
- Accept: 'application/json',
237
- },
238
255
  }
239
256
  return this._patch(options);
240
257
  }
@@ -250,10 +267,6 @@ class Api extends OAuth2Requester {
250
267
  const options = {
251
268
  url: this.baseUrl + this.URLs.getBatchContactsById,
252
269
  body,
253
- headers: {
254
- 'content-type': 'application/json',
255
- accept: 'application/json',
256
- },
257
270
  query: {
258
271
  archived: 'false',
259
272
  },
@@ -269,10 +282,6 @@ class Api extends OAuth2Requester {
269
282
  body: {
270
283
  properties: body,
271
284
  },
272
- headers: {
273
- 'Content-Type': 'application/json',
274
- Accept: 'application/json',
275
- },
276
285
  };
277
286
 
278
287
  return this._post(options);
@@ -302,7 +311,7 @@ class Api extends OAuth2Requester {
302
311
  async getDealStageHistory(dealId) {
303
312
  const options = {
304
313
  url: this.baseUrl + this.URLs.v1DealInfo(dealId),
305
- query: { includePropertyVersions: true },
314
+ query: {includePropertyVersions: true},
306
315
  };
307
316
  const res = await this._get(options);
308
317
  return res.properties.dealstage.versions;
@@ -352,9 +361,6 @@ class Api extends OAuth2Requester {
352
361
  const options = {
353
362
  url: this.baseUrl + this.URLs.searchDeals,
354
363
  body: searchBody,
355
- headers: {
356
- 'content-type': 'application/json',
357
- },
358
364
  };
359
365
  return this._post(options);
360
366
  }
@@ -362,7 +368,7 @@ class Api extends OAuth2Requester {
362
368
  async updateDeal(params) {
363
369
  const dealId = get(params, 'dealId');
364
370
  const properties = get(params, 'properties');
365
- const body = { properties };
371
+ const body = {properties};
366
372
  const options = {
367
373
  url: this.baseUrl + this.URLs.getDealById(dealId),
368
374
  body,
@@ -376,10 +382,6 @@ class Api extends OAuth2Requester {
376
382
  const options = {
377
383
  url: this.baseUrl + this.URLs.contactList,
378
384
  body,
379
- headers: {
380
- 'Content-Type': 'application/json',
381
- Accept: 'application/json',
382
- },
383
385
  };
384
386
 
385
387
  return this._post(options);
@@ -413,10 +415,6 @@ class Api extends OAuth2Requester {
413
415
  const options = {
414
416
  url: this.baseUrl + this.URLs.contactListById(listId),
415
417
  body,
416
- headers: {
417
- 'Content-Type': 'application/json',
418
- Accept: 'application/json',
419
- },
420
418
  };
421
419
  return this._post(options);
422
420
  }
@@ -427,14 +425,8 @@ class Api extends OAuth2Requester {
427
425
  const options = {
428
426
  url: this.baseUrl + this.URLs.customObjectSchemas,
429
427
  body,
430
- headers: {
431
- 'Content-Type': 'application/json',
432
- Accept: 'application/json',
433
- },
434
428
  };
435
- if (this.api_key) {
436
- options.query = { hapikey: this.api_key };
437
- }
429
+
438
430
 
439
431
  return this._post(options);
440
432
  }
@@ -459,17 +451,12 @@ class Api extends OAuth2Requester {
459
451
  return this._delete(options);
460
452
  }
461
453
 
462
- async getCustomObjectSchema(objectType) {
454
+ async getCustomObjectSchema(objectType, query) {
463
455
  const options = {
464
456
  url:
465
457
  this.baseUrl +
466
458
  this.URLs.customObjectSchemaByObjectType(objectType),
467
459
  };
468
-
469
- if (this.api_key) {
470
- options.query = { hapikey: this.api_key };
471
- }
472
-
473
460
  return this._get(options);
474
461
  }
475
462
 
@@ -477,11 +464,6 @@ class Api extends OAuth2Requester {
477
464
  const options = {
478
465
  url: this.baseUrl + this.URLs.customObjectSchemas,
479
466
  };
480
-
481
- if (this.api_key) {
482
- options.query = { hapikey: this.api_key };
483
- }
484
-
485
467
  return this._get(options);
486
468
  }
487
469
 
@@ -491,16 +473,7 @@ class Api extends OAuth2Requester {
491
473
  this.baseUrl +
492
474
  this.URLs.customObjectSchemaByObjectType(objectType),
493
475
  body,
494
- headers: {
495
- 'Content-Type': 'application/json',
496
- Accept: 'application/json',
497
- },
498
476
  };
499
-
500
- if (this.api_key) {
501
- options.query = { hapikey: this.api_key };
502
- }
503
-
504
477
  return this._patch(options);
505
478
  }
506
479
 
@@ -510,15 +483,7 @@ class Api extends OAuth2Requester {
510
483
  const options = {
511
484
  url: this.baseUrl + this.URLs.customObjects(objectType),
512
485
  body,
513
- headers: {
514
- 'Content-Type': 'application/json',
515
- Accept: 'application/json',
516
- },
517
486
  };
518
- if (this.api_key) {
519
- options.query = { hapikey: this.api_key };
520
- }
521
-
522
487
  return this._post(options);
523
488
  }
524
489
 
@@ -526,15 +491,7 @@ class Api extends OAuth2Requester {
526
491
  const options = {
527
492
  url: this.baseUrl + this.URLs.bulkCreateCustomObjects(objectType),
528
493
  body,
529
- headers: {
530
- 'Content-Type': 'application/json',
531
- Accept: 'application/json',
532
- },
533
494
  };
534
- if (this.api_key) {
535
- options.query = { hapikey: this.api_key };
536
- }
537
-
538
495
  return this._post(options);
539
496
  }
540
497
 
@@ -543,11 +500,6 @@ class Api extends OAuth2Requester {
543
500
  url: this.baseUrl + this.URLs.customObjectById(objectType, objId),
544
501
  query: {},
545
502
  };
546
-
547
- if (this.api_key) {
548
- options.query.hapikey = this.api_key;
549
- }
550
-
551
503
  return this._delete(options);
552
504
  }
553
505
 
@@ -557,13 +509,9 @@ class Api extends OAuth2Requester {
557
509
  const options = {
558
510
  method: 'POST',
559
511
  body: JSON.stringify(body),
560
- headers: {
561
- 'Content-Type': 'application/json',
562
- Accept: 'application/json',
563
- },
564
512
  query: {},
565
513
  };
566
-
514
+ this.addJsonHeaders(options);
567
515
  if (this.api_key) {
568
516
  options.query.hapikey = this.api_key;
569
517
  }
@@ -576,11 +524,6 @@ class Api extends OAuth2Requester {
576
524
  const options = {
577
525
  url: this.baseUrl + this.URLs.customObjectById(objectType, objId),
578
526
  };
579
-
580
- if (this.api_key) {
581
- options.query = { hapikey: this.api_key };
582
- }
583
-
584
527
  return this._get(options);
585
528
  }
586
529
 
@@ -588,15 +531,7 @@ class Api extends OAuth2Requester {
588
531
  const options = {
589
532
  url: this.baseUrl + this.URLs.bulkReadCustomObjects(objectType),
590
533
  body,
591
- headers: {
592
- 'Content-Type': 'application/json',
593
- Accept: 'application/json',
594
- },
595
534
  };
596
- if (this.api_key) {
597
- options.query = { hapikey: this.api_key };
598
- }
599
-
600
535
  return this._post(options);
601
536
  }
602
537
 
@@ -605,11 +540,6 @@ class Api extends OAuth2Requester {
605
540
  url: this.baseUrl + this.URLs.customObjects(objectType),
606
541
  query,
607
542
  };
608
-
609
- if (this.api_key) {
610
- options.query.hapikey = this.api_key;
611
- }
612
-
613
543
  return this._get(options);
614
544
  }
615
545
 
@@ -617,15 +547,7 @@ class Api extends OAuth2Requester {
617
547
  const options = {
618
548
  url: this.baseUrl + this.URLs.customObjectsSearch(objectType),
619
549
  body,
620
- headers: {
621
- 'Content-Type': 'application/json',
622
- Accept: 'application/json',
623
- },
624
550
  };
625
- if (this.api_key) {
626
- options.query = { hapikey: this.api_key };
627
- }
628
-
629
551
  return this._post(options);
630
552
  }
631
553
 
@@ -633,16 +555,7 @@ class Api extends OAuth2Requester {
633
555
  const options = {
634
556
  url: this.baseUrl + this.URLs.customObjectById(objectType, objId),
635
557
  body,
636
- headers: {
637
- 'Content-Type': 'application/json',
638
- Accept: 'application/json',
639
- },
640
558
  };
641
-
642
- if (this.api_key) {
643
- options.query = { hapikey: this.api_key };
644
- }
645
-
646
559
  return this._patch(options);
647
560
  }
648
561
 
@@ -650,14 +563,7 @@ class Api extends OAuth2Requester {
650
563
  const options = {
651
564
  url: this.baseUrl + this.URLs.bulkUpdateCustomObjects(objectType),
652
565
  body,
653
- headers: {
654
- 'Content-Type': 'application/json',
655
- Accept: 'application/json',
656
- },
657
566
  };
658
- if (this.api_key) {
659
- options.query = { hapikey: this.api_key };
660
- }
661
567
  return this._post(options);
662
568
  }
663
569
 
@@ -679,10 +585,6 @@ class Api extends OAuth2Requester {
679
585
  const options = {
680
586
  url: this.baseUrl + this.URLs.properties(objType),
681
587
  body,
682
- headers: {
683
- 'Content-Type': 'application/json',
684
- Accept: 'application/json',
685
- },
686
588
  };
687
589
 
688
590
  return this._post(options);
@@ -708,10 +610,6 @@ class Api extends OAuth2Requester {
708
610
  const options = {
709
611
  url: this.baseUrl + this.URLs.propertiesByName(objType, propName),
710
612
  body,
711
- headers: {
712
- 'Content-Type': 'application/json',
713
- Accept: 'application/json',
714
- },
715
613
  };
716
614
  return this._patch(options);
717
615
  }
@@ -749,7 +647,7 @@ class Api extends OAuth2Requester {
749
647
 
750
648
  // ************************** Pages *****************************
751
649
 
752
- async getLandingPages(query=''){
650
+ async getLandingPages(query = '') {
753
651
  const options = {
754
652
  url: `${this.baseUrl}${this.URLs.landingPages}`,
755
653
  };
@@ -759,28 +657,23 @@ class Api extends OAuth2Requester {
759
657
  return this._get(options);
760
658
  }
761
659
 
762
- async getLandingPage(id){
660
+ async getLandingPage(id) {
763
661
  const options = {
764
662
  url: `${this.baseUrl}${this.URLs.landingPageById(id)}`,
765
663
  };
766
664
  return this._get(options);
767
665
  }
768
666
 
769
- async updateLandingPage(objId, body, isDraft=false){
667
+ async updateLandingPage(objId, body, isDraft = false) {
770
668
  const draft = isDraft ? '/draft' : ''
771
669
  const options = {
772
670
  url: `${this.baseUrl}${this.URLs.landingPageById(objId)}${draft}`,
773
671
  body,
774
- headers: {
775
- 'Content-Type': 'application/json',
776
- Accept: 'application/json',
777
-
778
- }
779
672
  };
780
673
  return this._patch(options);
781
674
  }
782
675
 
783
- async pushLandingPageDraftToLive(objId){
676
+ async pushLandingPageDraftToLive(objId) {
784
677
  const options = {
785
678
  url: `${this.baseUrl}${this.URLs.landingPageById(objId)}/draft/push-live`,
786
679
  };
@@ -794,16 +687,11 @@ class Api extends OAuth2Requester {
794
687
  id: objId,
795
688
  publishDate
796
689
  },
797
- headers: {
798
- 'Content-Type': 'application/json',
799
- Accept: 'application/json',
800
-
801
- }
802
690
  };
803
691
  return this._post(options);
804
692
  }
805
693
 
806
- async getSitePages(query=''){
694
+ async getSitePages(query = '') {
807
695
  const options = {
808
696
  url: `${this.baseUrl}${this.URLs.sitePages}`,
809
697
  };
@@ -813,7 +701,7 @@ class Api extends OAuth2Requester {
813
701
  return this._get(options);
814
702
  }
815
703
 
816
- async getSitePage(id){
704
+ async getSitePage(id) {
817
705
  const options = {
818
706
  url: `${this.baseUrl}${this.URLs.sitePageById(id)}`,
819
707
  };
@@ -821,21 +709,16 @@ class Api extends OAuth2Requester {
821
709
  }
822
710
 
823
711
 
824
- async updateSitePage(objId, body, isDraft=false){
712
+ async updateSitePage(objId, body, isDraft = false) {
825
713
  const draft = isDraft ? '/draft' : ''
826
714
  const options = {
827
715
  url: `${this.baseUrl}${this.URLs.sitePageById(objId)}${draft}`,
828
716
  body: body,
829
- headers: {
830
- 'Content-Type': 'application/json',
831
- Accept: 'application/json',
832
-
833
- }
834
717
  };
835
718
  return this._patch(options);
836
719
  }
837
720
 
838
- async pushSitePageDraftToLive(objId){
721
+ async pushSitePageDraftToLive(objId) {
839
722
  const options = {
840
723
  url: `${this.baseUrl}${this.URLs.sitePageById(objId)}/draft/push-live`,
841
724
  };
@@ -849,18 +732,13 @@ class Api extends OAuth2Requester {
849
732
  id: objId,
850
733
  publishDate
851
734
  },
852
- headers: {
853
- 'Content-Type': 'application/json',
854
- Accept: 'application/json',
855
-
856
- }
857
735
  };
858
736
  return this._post(options);
859
737
  }
860
738
 
861
739
  // ************************** Blogs *****************************
862
740
 
863
- async getBlogPosts(query=''){
741
+ async getBlogPosts(query = '') {
864
742
  const options = {
865
743
  url: `${this.baseUrl}${this.URLs.blogPosts}`,
866
744
  };
@@ -870,28 +748,23 @@ class Api extends OAuth2Requester {
870
748
  return this._get(options);
871
749
  }
872
750
 
873
- async getBlogPost(id){
751
+ async getBlogPost(id) {
874
752
  const options = {
875
753
  url: `${this.baseUrl}${this.URLs.blogPostById(id)}`,
876
754
  };
877
755
  return this._get(options);
878
756
  }
879
757
 
880
- async updateBlogPost(objId, body, isDraft=false) {
758
+ async updateBlogPost(objId, body, isDraft = false) {
881
759
  const draft = isDraft ? '/draft' : ''
882
760
  const options = {
883
761
  url: `${this.baseUrl}${this.URLs.blogPostById(objId)}${draft}`,
884
762
  body: body,
885
- headers: {
886
- 'Content-Type': 'application/json',
887
- Accept: 'application/json',
888
-
889
- }
890
763
  };
891
764
  return this._patch(options);
892
765
  }
893
766
 
894
- async pushBlogPostDraftToLive(objId){
767
+ async pushBlogPostDraftToLive(objId) {
895
768
  const options = {
896
769
  url: `${this.baseUrl}${this.URLs.blogPostById(objId)}/draft/push-live`,
897
770
  };
@@ -905,18 +778,13 @@ class Api extends OAuth2Requester {
905
778
  id: objId,
906
779
  publishDate
907
780
  },
908
- headers: {
909
- 'Content-Type': 'application/json',
910
- Accept: 'application/json',
911
-
912
- }
913
781
  };
914
782
  return this._post(options);
915
783
  }
916
784
 
917
785
  // *********************** Email Templates **************************
918
786
 
919
- async getEmailTemplates(query=''){
787
+ async getEmailTemplates(query = '') {
920
788
  const options = {
921
789
  url: `${this.baseUrl}${this.URLs.emailTemplates}`,
922
790
  };
@@ -926,7 +794,7 @@ class Api extends OAuth2Requester {
926
794
  return this._get(options);
927
795
  }
928
796
 
929
- async getEmailTemplate(id){
797
+ async getEmailTemplate(id) {
930
798
  const options = {
931
799
  url: `${this.baseUrl}${this.URLs.emailTemplateById(id)}`,
932
800
  };
@@ -937,11 +805,6 @@ class Api extends OAuth2Requester {
937
805
  const options = {
938
806
  url: `${this.baseUrl}${this.URLs.emailTemplateById(objId)}`,
939
807
  body: body,
940
- headers: {
941
- 'Content-Type': 'application/json',
942
- Accept: 'application/json',
943
-
944
- }
945
808
  };
946
809
  return this._put(options);
947
810
  }
@@ -950,16 +813,11 @@ class Api extends OAuth2Requester {
950
813
  const options = {
951
814
  url: `${this.baseUrl}${this.URLs.emailTemplates}`,
952
815
  body: body,
953
- headers: {
954
- 'Content-Type': 'application/json',
955
- Accept: 'application/json',
956
-
957
- }
958
816
  };
959
817
  return this._post(options);
960
818
  }
961
819
 
962
- async deleteEmailTemplate(id){
820
+ async deleteEmailTemplate(id) {
963
821
  const options = {
964
822
  url: `${this.baseUrl}${this.URLs.emailTemplateById(id)}`,
965
823
  };
@@ -973,7 +831,7 @@ class Api extends OAuth2Requester {
973
831
  url: this.baseUrl + this.URLs.userDetails,
974
832
  });
975
833
  const url2 = this.URLs.domain(this.access_token);
976
- const res2 = await this._get({ url: this.baseUrl + url2 });
834
+ const res2 = await this._get({url: this.baseUrl + url2});
977
835
  return Object.assign(res1, res2);
978
836
  }
979
837
 
@@ -984,29 +842,73 @@ class Api extends OAuth2Requester {
984
842
  return this._get(options);
985
843
  }
986
844
 
987
- async batchGetAssociations(params) {
988
- const fromObject = get(params, 'fromObject');
989
- const toObject = get(params, 'toObject');
990
- const inputs = get(params, 'inputs');
845
+ async getBatchAssociations(fromObjectType, toObjectType, inputs) {
846
+ const postBody = {inputs};
847
+
848
+ const options = {
849
+ url:
850
+ this.baseUrl +
851
+ this.URLs.readBatchAssociations(fromObjectType, toObjectType),
852
+ body: postBody,
853
+ };
854
+
855
+ const res = await this._post(options);
856
+ const {results} = res;
857
+ return results;
858
+ }
991
859
 
992
- const postBody = { inputs };
860
+ async createBatchAssociations(fromObjectType, toObjectType, inputs) {
861
+ const postBody = {inputs};
993
862
 
994
863
  const options = {
995
864
  url:
996
865
  this.baseUrl +
997
- this.URLs.getBatchAssociations(fromObject, toObject),
866
+ this.URLs.createBatchAssociations(fromObjectType, toObjectType),
998
867
  body: postBody,
999
- headers: {
1000
- 'content-type': 'application/json',
1001
- accept: 'application/json',
1002
- },
1003
868
  };
1004
869
 
1005
870
  const res = await this._post(options);
1006
- const { results } = res;
871
+ const {results} = res;
872
+ return results;
873
+ }
874
+
875
+ async createBatchAssociationsDefault(fromObjectType, toObjectType, inputs) {
876
+ const options = {
877
+ url:
878
+ this.baseUrl +
879
+ this.URLs.createBatchAssociationsDefault(fromObjectType, toObjectType),
880
+ body: {inputs},
881
+ };
882
+
883
+ const res = await this._post(options);
884
+ const {results} = res;
1007
885
  return results;
1008
886
  }
1009
887
 
888
+ async deleteBatchAssociations(fromObjectType, toObjectType, inputs) {
889
+ const options = {
890
+ url:
891
+ this.baseUrl +
892
+ this.URLs.deleteBatchAssociations(fromObjectType, toObjectType),
893
+ body: {inputs},
894
+ returnFullRes: true,
895
+ };
896
+
897
+ return this._post(options);
898
+ }
899
+
900
+ async deleteBatchAssociationLabels(fromObjectType, toObjectType, inputs) {
901
+ const options = {
902
+ url:
903
+ this.baseUrl +
904
+ this.URLs.deleteBatchAssociationLabels(fromObjectType, toObjectType),
905
+ body: {inputs},
906
+ returnFullRes: true,
907
+ };
908
+
909
+ return this._post(options);
910
+ }
911
+
1010
912
  async _propertiesList(objType) {
1011
913
  const props = await this.listProperties(objType);
1012
914
  let propsString = '';
@@ -1016,6 +918,96 @@ class Api extends OAuth2Requester {
1016
918
  propsString = propsString.slice(0, propsString.length - 1);
1017
919
  return propsString;
1018
920
  }
921
+
922
+ async getAssociationLabels(fromObjType, toObjType) {
923
+ const options = {
924
+ url: this.baseUrl + this.URLs.associationLabels(fromObjType, toObjType),
925
+ };
926
+ return this._get(options);
927
+ }
928
+
929
+ async createAssociationLabel(fromObjType, toObjType, label) {
930
+ const options = {
931
+ url: this.baseUrl + this.URLs.associationLabels(fromObjType, toObjType),
932
+ body: label
933
+ };
934
+ return this._post(options);
935
+ }
936
+
937
+ async deleteAssociationLabel(fromObjType, toObjType, associationTypeId) {
938
+ const options = {
939
+ url: this.baseUrl + this.URLs.associationLabels(fromObjType, toObjType) + `/${associationTypeId}`,
940
+ };
941
+ return this._delete(options, false);
942
+ }
943
+
944
+ async searchLists(query = "", offset = 0, count = 500, additionalProperties = []) {
945
+ const options = {
946
+ url: this.baseUrl + this.URLs.listSearch,
947
+ body: {
948
+ query,
949
+ offset,
950
+ count,
951
+ additionalProperties
952
+ },
953
+ };
954
+ return this._post(options);
955
+ }
956
+
957
+ async getListById(listId) {
958
+ const options = {
959
+ url: this.baseUrl + this.URLs.listById(listId),
960
+ };
961
+ return this._get(options);
962
+ }
963
+
964
+ async createList(name, objectTypeId, processingType = 'MANUAL', listFolderId = null) {
965
+ const options = {
966
+ url: this.baseUrl + this.URLs.lists,
967
+ body: {
968
+ name,
969
+ objectTypeId,
970
+ processingType,
971
+ listFolderId
972
+ },
973
+ };
974
+ return this._post(options);
975
+ }
976
+
977
+ async deleteList(listId) {
978
+ const options = {
979
+ url: this.baseUrl + this.URLs.listById(listId),
980
+ };
981
+ return this._delete(options);
982
+ }
983
+
984
+ async removeAllListMembers(listId) {
985
+ const options = {
986
+ url: this.baseUrl + this.URLs.listMemberships(listId),
987
+ };
988
+ return this._delete(options);
989
+ }
990
+
991
+ async addAndRemoveFromList(listId, idsToAdd, idsToRemove) {
992
+ const options = {
993
+ url: this.baseUrl + this.URLs.listMembershipsAddRemove(listId),
994
+ body: {
995
+ "recordIdsToAdd": idsToAdd,
996
+ "recordIdsToRemove": idsToRemove
997
+ },
998
+ };
999
+ return this._put(options);
1000
+ }
1001
+
1002
+ async addToList(listId, recordIds) {
1003
+ return this.addAndRemoveFromList(listId, recordIds, []);
1004
+ }
1005
+
1006
+ async removeFromList(listId, recordIds) {
1007
+ return this.addAndRemoveFromList(listId, [], recordIds);
1008
+ }
1009
+
1010
+
1019
1011
  }
1020
1012
 
1021
- module.exports = { Api };
1013
+ module.exports = {Api};