-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.js
2307 lines (2260 loc) · 104 KB
/
Code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* GetResponse API wrappie for Google Apps Script
* @name GetResponse
* @class GetResponse
* @param {string} type type of account used, possible values: enterprise|360 for users of GR Enterprise, smb|retail for users of "usual" GR
* @param {string} apiKey api key which can be obtained and created in the account
* @param {string} env environment of enterprise account, possible values: pl, us. Not required for SMB accounts
* @param {string} domain enterprise domain without http(s) and www, not requited for SMB accounts
* @returns {Object} list of GR API methods
*/
function GetResponse(type, apiKey, env, domain) {
function isObject(item) {
return typeof item === 'object' && item.constructor !== Array && item !== null;
}
function getUrl(type, env) {
var baseUrl = '';
if (type == '360' || type.toLowerCase() === 'enterprise') {
if (env.toLowerCase() === 'pl') {
baseUrl = 'https://api3.getresponse360.pl/v3/';
} else if (env.toLowerCase() === 'us') {
baseUrl = 'https://api3.getresponse360.com/v3/';
} else {
var check = JSON.parse(checkEnvironment());
env = check.env;
return check.baseUrl;
}
} else if (type.toLowerCase() === 'retail' || type.toLowerCase() === 'smb') {
baseUrl = 'https://api.getresponse.com/v3/';
}
return baseUrl;
}
var baseUrl = getUrl(type, env);
function checkEnvironment() {
if (type === 'retail') {
return this.get('accounts');
}
var envs = [{
env: 'pl',
domain: domain,
type: 'enterprise',
baseUrl: 'https://api3.getresponse360.pl/v3/'
},
{
env: 'us',
domain: domain,
type: 'enterprise',
baseUrl: 'https://api3.getresponse360.com/v3/'
}
];
for (var i in envs) {
var response = sendRequest_(envs[i].type, envs[i].env, apiKey, envs[i].domain, envs[i].baseUrl, 'accounts', 'get', '');
var responseCode = response.getResponseCode();
if (response.httpStatus === 404 && response.message === 'Incorrect environment') {
continue;
} else {
response = JSON.parse(response);
if (responseCode <= 299) {
env = envs[i].env;
return JSON.stringify(envs[i]);
}
}
}
return JSON.stringify({
error: true,
code: '0',
httpStatus: 404,
message: 'No matching environment: probably an SMB account or just wrong credentials'
});
};
function sendRequest_(type, env, apiKey, domain, baseUrl, request, method, body) {
var url = baseUrl + request;
var headers = {
'X-Auth-Token': 'api-key ' + apiKey
};
if (domain) headers['X-DOMAIN'] = domain;
var options = {
headers: headers,
contentType: 'application/json',
method: method,
payload: body,
muteHttpExceptions: true
};
Logger.log(url);
var response = UrlFetchApp.fetch(url, options);
var responseCode = response.getResponseCode();
//If GR360 credentials contain wrong environment code or wrong domain, an html page will be returned.
//If this happens, an error object is created to be returned later on
var responseString = response.toString();
if (responseString.indexOf('<!DOCTYPE html>') != -1) {
response = {
error: true,
code: '0',
httpStatus: 404,
getResponseCode: function () {
return 404;
},
message: 'Incorrect environment'
};
}
return response;
}
// Written by Amit Agarwal www.labnol.org
function uploadFile_(type, env, apiKey, domain, baseUrl, blob) {
var url = baseUrl + "multimedia/";
if (!domain) domain = "";
var headers = {
"X-DOMAIN": domain,
"X-Auth-Token": "api-key " + apiKey
};
var boundary = "labnol";
var attributes = "{\"name\":\"" + blob.getName() + "\"}";
var requestBody = Utilities.newBlob(
"--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=\"attributes\"\r\n\r\n" +
attributes + "\r\n" + "--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=\"file\"; filename=\"" + blob.getName() + "\"\r\n" +
"Content-Type: " + blob.getContentType() + "\r\n\r\n").getBytes()
.concat(blob.getBytes())
.concat(Utilities.newBlob("\r\n--" + boundary + "--\r\n").getBytes());
var options = {
"method": "post",
"contentType": "multipart/form-data; boundary=" + boundary,
"payload": requestBody,
"muteHttpExceptions": false,
"headers": headers
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
return response;
}
function prepareRequest(request, parameters) {
request = request.trim();
if (request[request.length - 1] !== '/') {
request += '/';
}
if (parameters) {
request += queryGenerator(parameters);
}
return request;
}
function queryGenerator(parameters) {
if (parameters === undefined) {
return '';
}
if (typeof parameters === 'string' && parameters[0] === '?') {
return parameters;
}
var queryString = '?';
if (isObject(parameters.query)) {
for (var i in parameters.query) {
if (i === 'createdOn' || i === 'sendOn' || i === 'changedOn') {
for (var j in parameters.query[i]) {
if (!parameters.query[i][j]) continue;
queryString +=
'query[' + i + '][' + j + ']=' + encodeURIComponent(parameters.query[i][j]) + '&';
}
} else {
queryString += 'query[' + i + ']=' + encodeURIComponent(parameters.query[i]) + '&';
}
}
}
if (isObject(parameters.sort)) {
for (var k in parameters.sort) {
if (!parameters.sort[k]) continue
queryString += 'sort[' + k + ']=' + encodeURIComponent(parameters.sort[k]) + '&';
}
}
for (var k in parameters) {
if (!parameters[k]) continue;
if (k !== 'query' && k !== 'sort') {
queryString += k + '=' + encodeURIComponent(parameters[k]) + '&';
}
}
return queryString;
}
var self = {
apiKey: apiKey,
type: type || 'retail',
env: env || '',
domain: domain || '',
baseUrl: baseUrl,
get: function (request, parameters) {
var method = 'get';
request = prepareRequest(request, parameters);
return sendRequest_(this.type, this.env, this.apiKey, this.domain, this.baseUrl, request, method, '');
},
post: function (request, body) {
var method = 'post';
return sendRequest_(this.type, this.env, this.apiKey, this.domain, this.baseUrl, request, method, JSON.stringify(body));
},
remove: function (request, parameters) {
var method = 'delete';
request = prepareRequest(request, parameters);
return sendRequest_(this.type, this.env, this.apiKey, this.domain, this.baseUrl, request, method, '');
},
upload: function (blob) {
return uploadFile_(this.type, this.env, this.apiKey, this.domain, this.baseUrl, blob);
}
};
var methods = {};
methods.queryGenerator = queryGenerator;
/**
* @memberof GetResponse#
* @namespace contacts
*/
/**
* @name getContacts
* @description gets list of contacts according to parameters
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.get.all}
* @memberof GetResponse#
* @method getContacts
* @param {Object | string} parameters query parameters as object or as query string
* @example
* var query = {
* query: {
* createdOn: {
* from: '2018-01-01',
* to: '2018-03-01'
* },
* origin: 'api',
* },
* sort: {
* createdOn: 'desc'
* },
* perPage: 1000,
* page: 1
* };
* //the same object as above can set as query string:
* var queryString = '?query[createdOn][form]=2018-01-01&query[createdOn][to]=2018-03-01&query[origin]=api&sort[createdOn]=desc&perPage=1000&page=1';
* var contacts = JSON.parse(gr.contacts.get(query));
* var sheet = SpreadsheetApp.getActiveSheet();
* var array = [];
* for (var i in contacts) {
* array.push([contacts[i].email, contacts[i].createdOn]);
* }
* sheet.getRange(2, 1, array.length, array[0].length).setValues(array); //sets emails and subscription dates into a spreadsheet
* @returns {array} array of contact objects
*/
methods.getContacts = function (parameters) {
return self.get('contacts', parameters);
}
/**
* @name getContact
* @description get a single contact object by its id
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.get}
* @memberof GetResponse#
* @method contacts#getContact
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} contact
*/
methods.getContact = function (contactId, fields) {
return self.get('contacts/' + contactId, {
fields: fields
});
}
/**
* @name create
* @description create a new contact
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.create}
* @memberof GetResponse#
* @method contacts#createContact
* @param {object} contact contact object
* @returns {object} newly created contact object
*/
methods.createContact = function (contact) {
return self.post('contacts', contact);
}
/**
* @name update
* @description updates contact
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.update}
* @memberof GetResponse#
* @method contacts#updateContact
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {object} contact contact object
* @returns {object} updated contact
*/
methods.updateContact = function (contactId, contact) {
return self.post('contacts/' + contactId, contact);
}
/**
* @name updateContactCustoms
* @description update contact custom
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.upsert.custom-fields}
* @memberof GetResponse#
* @method contacts#updateContactCustoms
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {array} customs array of {@link GetResponse#customFields custom field} objects
* @returns {object} updated contact
*/
methods.updateContactCustoms = function (contactId, customs) {
return self.post('contacts/' + contactId + '/custom-fields', {
customFieldValues: customs
});
}
/**
* @name updateContactTags
* @description update contact tags
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.upsert.tags}
* @memberof GetResponse#
* @method contacts#updateContactTags
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {array} tags array of {@link GetResponse#tags tag} objects
* @returns {object} updated contact
*/
methods.updateContactTags = function (contactId, tags) {
return self.post('contacts/' + contactId + '/tags', {
tags: tags
});
}
/**
* @name getContactActivities
* @description gets activities of a contacts
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.get.activities}
* @memberof GetResponse#
* @method contacts#getContactActivities
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {object|string} parameters query parameters set as object or query string
* @returns array of contact activities
*/
methods.getContactActivities = function (contactId, parameters) {
return self.get('contacts/' + contactId + '/activities', parameters);
}
/**
* @name deleteContact
* @description deletes a contact by id
* @see {@link https://apidocs.getresponse.com/v3/resources/contacts#contacts.delete}
* @memberof GetResponse#
* @method contacts#deleteContact
* @param {string} contactId contact's id obtained via {@link GetResponse#contacts#getContacts getContacts} method
* @param {object} parameters in this case parameters may include: messageId, ipAddress and reason which can be equal to 'api' or 'unsubscribe'
*/
methods.deleteContact = function (contactId, parameters) {
return self.remove('contacts/' + contactId, parameters);
}
/**
* @memberof GetResponse#
* @namespace newsletters
*/
/**
* @name getNewsletters
* @description gets the list of newsletters
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.get.all}
* @memberof GetResponse#
* @method newsletters#getNewsletters
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} array of newsletters
*/
methods.getNewsletters = function (parameters) {
return self.get('newsletters', parameters);
}
/**
* @name getNewsletter
* @description gets one newsletter object with explicit information about it
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.get}
* @memberof GetResponse#
* @method newsletters#getNewsletter
* @param {string} newsletterId newsletter's id obtained via {@link GetResponse#newsletters#getNewsletters getNewsletters} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} newsletter
*/
methods.getNewsletter = function (newsletterId, fields) {
return self.get('newsletters/' + newsletterId, {
fields: fields
});
}
/**
* @name getNewslettersStats
* @description returns combined statistics of one or more newsletters
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.statistics.get.all}
* @memberof GetResponse#
* @method newsletters#getNewslettersStats
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} statistics
*/
methods.getNewslettersStats = function (parameters) {
return self.get('newsletters/statistics', parameters);
}
/**
* @name getNewsletterStats
* @description returns statistics of one newsletter according to params
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.statistics.get}
* @memberof GetResponse#
* @method newsletters#getNewsletterStats
* @param {string} newsletterId newsletter's id obtained via {@link GetResponse#newsletters#getNewsletters getNewsletters} method
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} statistics
*/
methods.getNewsletterStats = function (newsletterId, parameters) {
return self.get('newsletter/' + newsletterId + '/statisitcs', parameters);
}
/**
* @name createNewsletter
* @description creates draft and newsletters
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.create}
* @memberof GetResponse#
* @method newsletters#createNewsletter
* @param {object} newsletter newsletter object
* @returns {object} newsletter object
*/
methods.createNewsletter = function (newsletter) {
return self.post('newsletters', newsletter);
}
/**
* @name sendDraft
* @description sends a previously created draft immediately or schedules it for the necessary tome
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.send.draft}
* @memberof GetResponse#
* @method newsletters#sendDraft
* @param {object} draftSettings setting of the draft: messageId and sending settings, like time, recipients' ids, etc.
* @returns {object} newsletter object
*/
methods.sendDraft = function (draftSettings) {
return self.post('send-draft', draftSettings);
}
/**
* @name cancelNewsletter
* @description cancels a scheduled or currently sending messages
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.cancel}
* @memberof GetResponse#
* @method newsletters#cancelNewsletter
* @param {string} newsletterId newsletter's id obtained via {@link GetResponse#newsletters#getNewsletters getNewsletters} method
*/
methods.cancelNewsletter = function (newsletterId) {
return self.post('newsletters/' + newsletterId);
}
/**
* @name deleteNewsletter
* @description deletes a newsletter by its id
* @see {@link https://apidocs.getresponse.com/v3/resources/newsletters#newsletters.delete}
* @memberof GetResponse#
* @method newsletters#deleteNewsletter
* @param {string} newsletterId newsletter's id obtained via {@link GetResponse#newsletters#getNewsletters getNewsletters} method
*/
methods.deleteNewsletter = function (newsletterId) {
return self.remove('newsletters/' + newsletterId);
}
/**
* @memberof GetResponse#
* @namespace campaigns
*/
/**
* @name getCampaigns
* @description get list of campaigns with some information about them
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.get.all}
* @memberof GetResponse#
* @method campaigns#getCampaigns
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of campaigns
*/
methods.getCampaigns = function (parameters) {
return self.get('campaigns', parameters);
}
/**
* @name getCampaign
* @description get full information about a campaign
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.get}
* @memberof GetResponse#
* @method campaigns#getCampaign
* @param {string} campaignId campaign's id obtained via {@link GetResponse#campaigns#getCampaigns getCampaigns} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} campaign
*/
methods.getCampaign = function (campaignId, fields) {
return self.get('campaigns/' + campaignId, {
fields: fields
});
}
/**
* @name getCampaignContacts
* @description get list of contacts subscribed to this campaign
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.contacts.get}
* @memberof GetResponse#
* @method campaigns#getCampaignContacts
* @param {string} campaignId campaign's id obtained via {@link GetResponse#campaigns#getCampaigns getCampaigns} method
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of contacts
*/
methods.getCampaignContacts = function (campaignId, parameters) {
return self.get('campaigns/' + campaignId + '/contacts', parameters);
}
/**
* @name getCampaignBlacklist
* @description get list of masks from the campaign's blacklist
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.blacklists.get}
* @memberof GetResponse#
* @method campaigns#getCampaignBlacklist
* @param {string} campaignId campaign's id obtained via {@link GetResponse#campaigns#getCampaigns getCampaigns} method
* @param {object|string} parameters query parameters set as object or query string
* @returns {object} object which contains the array with blacklisted masks
*/
methods.getCampaignBlacklist = function (campaignId, parameters) {
return self.get('campaigns/' + campaignId + '/blacklists', parameters);
}
/**
* @name getCampaignsListSize
* @description get statistics on the number of emails in the specified campaign(s)
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.statistics.list-size}
* @memberof GetResponse#
* @method campaigns#getCampaignsListSize
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of objects with statistics on list size for specified campaigns
*/
methods.getCampaignsListSize = function (parameters) {
return self.get('campaigns/statistics/list-size', parameters);
}
/**
* @name getCampaignsLocations
* @description get statistics on locations of subscribers in specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.statistics.locations}
* @memberof GetResponse#
* @method campaigns#getCampaignsLocations
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of campaign locations
*/
methods.getCampaignsLocations = function (parameters) {
return self.get('campaigns/statistics/locations', parameters);
}
/**
* @name getCampaignsOrigins
* @description get statistics on subscription methods for specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.statistics.origins}
* @memberof GetResponse#
* @method campaigns#getCampaignsOrigins
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getCampaignsOrigins = function (parameters) {
return self.get('campaigns/statistics/origins', parameters);
}
/**
* @name getCampaignsRemovals
* @description get statistics on unsubscribes and other removals from specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.statistics.removals}
* @memberof GetResponse#
* @method campaigns#getCampaignsRemovals
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getCampaignsRemovals = function (parameters) {
return self.get('campaigns/statistics/removals', parameters);
}
/**
* @name getCampaignsSubscriptions
* @description get statistics on subscriptions to specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.statistics.subscriptions}
* @memberof GetResponse#
* @method campaigns#getCampaignsSubscriptions
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getCampaignsSubscriptions = function (parameters) {
return self.get('campaigns/statistics/subscriptions', parameters);
}
/**
* @name getCampaignsBalance
* @description get statistics on removals from and subscriptions to specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.get.balance}
* @memberof GetResponse#
* @method campaigns#getCampaignsBalance
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getCampaignsBalance = function (parameters) {
return self.get('campaigns/statistics/balance', parameters);
}
/**
* @name getCampaignsSummary
* @description get current basic statistics of specified campaigns
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.get.summary}
* @memberof GetResponse#
* @method campaigns#getCampaignsSummary
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getCampaignsSummary = function (parameters) {
return self.get('campaigns/statistics/summary', parameters);
}
/**
* @name createCampaign
* @description create a new campaign
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.create}
* @memberof GetResponse#
* @method campaigns#createCampaign
* @param {object} campaign campaign settings
* @returns {object} campaign object
*/
methods.createCampaign = function (campaign) {
return self.post('campaigns', campaign);
}
/**
* @name updateCampaign
* @description updates a campaign
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.update}
* @memberof GetResponse#
* @method campaigns#updateCampaign
* @param {string} campaignId campaign's id obtained via {@link GetResponse#campaigns#getCampaigns getCampaigns} method
* @param {object} settings campaign settings
* @returns {object} campaign object
*/
methods.updateCampaign = function (campaignId, settings) {
return self.post('campaigns/' + campaignId, settings);
}
/**
* @name updateCampaignBlacklist
* @description replace masks in the campaign blacklist with the new ones
* @see {@link https://apidocs.getresponse.com/v3/resources/campaigns#campaigns.blacklists.update}
* @memberof GetResponse#
* @method campaigns#updateCampaignBlacklist
* @param {string} campaignId campaign's id obtained via {@link GetResponse#campaigns#getCampaigns getCampaigns} method
* @param {array} masks array of masks to add into blacklists. Masks should always contain @ character
* @returns {object} object with newly added masks
*/
methods.updateCampaignBlacklist = function (campaignId, masks) {
return self.post('campaign/' + campaignId + '/blacklists', {
masks: masks
});
}
/**
* @memberof GetResponse#
* @namespace autoresponders
*/
/**
* @name getAutoresponders
* @description gets the list of autoresponders
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.get.all}
* @memberof GetResponse#
* @method autoresponders#getAutoresponders
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of autoresponder objects
*/
methods.getAutoresponders = function (parameters) {
return self.get('autoresponders', parameters);
}
/**
* @name getAutoresponder
* @description get full info about one autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.get}
* @memberof GetResponse#
* @method autoresponders#getAutoresponder
* @param {string} autoresponderId autoresponder's id obtained via {@link GetResponse#autoresponders#getAutoresponders getAutoresponders} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} autoresponder object
*/
methods.getAutoresponder = function (autoresponderId, fields) {
return self.get('autoresponders/' + autoresponderId, {
fields: fields
});
}
/**
* @name getAutorespondersStats
* @description get statistics of one or more autoresponders
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.statistics.get.all}
* @memberof GetResponse#
* @method autoresponders#getAutorespondersStats
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getAutorespondersStats = function (parameters) {
return self.get('autoresponders/statistics', parameters);
}
/**
* @name getAutoresponderStats
* @description get statistics of one autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.statistics.get}
* @memberof GetResponse#
* @method autoresponders#getAutoresponderStats
* @param {string} autoresponderId autoresponder's id obtained via {@link GetResponse#autoresponders#getAutoresponders getAutoresponders} method
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} collection of statistics objects
*/
methods.getAutoresponderStats = function (autoresponderId, parameters) {
return self.get('autoresponders/' + autoresponderId + '/statistics', parameters);
}
/**
* @name getAutoresponderThumbnail
* @description get thumbnail of an autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.get.thumbnail}
* @memberof GetResponse#
* @method autoresponders#getAutoresponderThumbnail
* @param {string} autoresponderId autoresponder's id obtained via {@link GetResponse#autoresponders#getAutoresponders getAutoresponders} method
* @param {string} size size of the thumbnail to be returned. Possible values: default, small
* @returns thumbnail
*/
methods.getAutoresponderThumbnail = function (autoresponderId, size) {
return self.get('autoresponders/' + autoresponderId + '/thumbnail', {
size: size
});
}
/**
* @name createAutoresponder
* @description creates an autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.create}
* @memberof GetResponse#
* @method autoresponders#createAutoresponder
* @param {object} autoresponder autoresponder object
* @returns {object} autoresponder object
*/
methods.createAutoresponder = function (autoresponder) {
return self.post('autoresponders', autoresponder);
}
/**
* @name updateAutoresponder
* @description updates an autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.update}
* @memberof GetResponse#
* @method autoresponders#updateAutoresponder
* @param {string} autoresponderId autoresponder's id obtained via {@link GetResponse#autoresponders#getAutoresponders getAutoresponders} method
* @param {object} autoresponderSettings autoresponder object
* @returns {object} autoresponder object
*/
methods.updateAutoresponder = function (autoresponderId, autoresponderSettings) {
return self.post('autoresponders/' + autoresponderId, autoresponderSettings);
}
/**
* @name deleteAutoresponder
* @description deletes an autoresponder
* @see {@link https://apidocs.getresponse.com/v3/resources/autoresponders#autoresponders.delete}
* @memberof GetResponse#
* @method autoresponders#deleteAutoresponder
* @param {string} autoresponderId autoresponder's id obtained via {@link GetResponse#autoresponders#getAutoresponders getAutoresponders} method
*/
methods.deleteAutoresponder = function (autoresponderId) {
return self.remove('autoresponders/' + autoresponderId);
}
/**
* @memberof GetResponse#
* @namespace rssNewsletters
*/
/**
* @description gets the list of RSS newsletters
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters#get.all}
* @memberof GetResponse#
* @method rssNewsletters#getRssNewsletters
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} list of RSS newsletter objects
*/
methods.getRssNewsletters = function (parameters) {
return self.get('rss-newsletters', parameters);
}
/**
* @description gets full info about one RSS newsletter
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters.get}
* @memberof GetResponse#
* @method rssNewsletters#getRssNewsletter
* @param {string} newsletterId RSS newsletter's id obtained via {@link GetResponse#rssNewsletters#getRssNewsletters getRssNewsletters} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} RSS newsletter object
*/
methods.getRssNewsletter = function (newsletterId, fields) {
return self.get('rss-newsletters/' + newsletterId, {
fields: fields
});
}
/**
* @description gets statistics combined on one or more RSS newsletters
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters.statistics.get.all}
* @memberof GetResponse#
* @method rssNewsletters#getRssNewslettersStats
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} array of statistics objects
*/
methods.getRssNewslettersStats = function (parameters) {
return self.get('rss-newsletters/statistics', parameters);
}
/**
* @description get statistics on one RSS newsletter
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters#statistics.get}
* @memberof GetResponse#
* @method rssNewsletters#getRssNewsletterStats
* @param {string} newsletterId RSS newsletter's id obtained via {@link GetResponse#rssNewsletters#getRssNewsletters getRssNewsletters} method
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} array of statistics objects
*/
methods.getRssNewsletterStats = function (newsletterId, parameters) {
return self.get('rss-newsletters/' + newsletterId + '/statistics', parameters);
}
/**
* @description creates a new RSS newsletter according to parameters
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters#create}
* @memberof GetResponse#
* @method rssNewsletters#createRssNewsletter
* @param {object} newsletter newsletter object
* @returns {object} newly created newsletter object
*/
methods.createRssNewsletter = function (newsletter) {
return self.post('rss-newsletters', newsletter);
}
/**
* @description updates an RSS newsletter
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters#update}
* @memberof GetResponse#
* @method rssNewsletters#updateRssNewsletter
* @param {string} newsletterId RSS newsletter's id obtained via {@link GetResponse#rssNewsletters#getRssNewsletters getRssNewsletters} method
* @param {object} newsletter newsletter object
* @returns {object} updated newsletter object
*/
methods.updateRssNewsletter = function (newsletterId, newsletter) {
return self.post('rss-newsletters/' + newsletterId, newsletter);
}
/**
* @description deletes an RSS newsletter
* @see {@link https://apidocs.getresponse.com/v3/resources/rss-newsletters#rss-newsletters#delete}
* @memberof GetResponse#
* @method rssNewsletters#deleteRssNewsletter
* @param {string} newsletterId RSS newsletter's id obtained via {@link GetResponse#rssNewsletters#getRssNewsletters getRssNewsletters} method
*/
methods.deleteRssNewsletter = function (newsletterId) {
return self.remove('rss-newsletters/' + newsletterId);
}
/**
* @memberof GetResponse#
* @namespace fromFields
*/
/**
* @description gets from fields that are accessible in the account
* @see {@link https://apidocs.getresponse.com/v3/resources/fromfields#fromfields.get.all}
* @memberof GetResponse#
* @method fromFields#getFromFields
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} array of from fields objects
*/
methods.getFromFields = function (parameters) {
return self.get('from-fields', parameters);
}
/**
* @description gets full info about one from field
* @see {@link https://apidocs.getresponse.com/v3/resources/fromfields#fromfields.get}
* @memberof GetResponse#
* @method fromFields#getFromField
* @param {string} fromFieldId from field's id obtained via {@link GetResponse#fromFields#getFromFields getFromFields} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned.
* @returns {object} from field object
*/
methods.getFromField = function (fromFieldId, fields) {
return self.get('from-fields/' + fromFieldId, {
fields: fields
});
}
/**
* @description creates a new from field
* @see {@link https://apidocs.getresponse.com/v3/resources/fromfields#fromfields.create}
* @memberof GetResponse#
* @method fromFields#createFromField
* @param {string} email email of the from field
* @param {string} name name of the from field
* @returns {object} newly created from field
*/
methods.createFromField = function (email, name) {
return self.post('from-fields', {
email: email,
name: name
})
}
/**
* @description sets from field as default
* @see {@link https://apidocs.getresponse.com/v3/resources/fromfields#fromfields.default}
* @memberof GetResponse#
* @method fromFields#setFromFieldAsDefault
* @param {string} fromFieldId from field's id obtained via {@link GetResponse#fromFields#getFromFields getFromFields} method
* @returns {object} updated from field object
*/
methods.setFromFieldAsDefault = function (fromFieldId) {
return self.post('from-fields/' + fromFieldId + '/default');
}
/**
* @description deletes a from field
* @see {@link https://apidocs.getresponse.com/v3/resources/fromfields#fromfields.delete}
* @memberof GetResponse#
* @method fromFields#deleteFromField
* @param {string} fromFieldIdToRemove from field's (which is to be removed) id obtained via {@link GetResponse#fromFields#getFromFields getFromFields} method
* @param {string} fromFieldIdToReplaceWith from field's (which is to replace the removed one in newsletters and autoresponders) id obtained via {@link GetResponse#fromFields#getFromFields getFromFields} method
* @returns {number} statusCode
*/
methods.deleteFromField = function (fromFieldIdToRemove, fromFieldIdToReplaceWith) {
return self.remove('from-fields/' + fromFieldIdToRemove, '', {
fromFieldIdToReplaceWith: fromFieldIdToReplaceWith
});
}
/**
* @memberof GetResponse#
* @namespace customFields
*/
/**
* @description gets list of available custom fields
* @see {@link https://apidocs.getresponse.com/v3/resources/customfields#customfields.get.all}
* @memberof GetResponse#
* @method customFields#getCustomFields
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} array of custom field objects
*/
methods.getCustomFields = function (parameters) {
return self.get('custom-fields', parameters);
}
/**
* @description gets full info about one custom field
* @see {@link https://apidocs.getresponse.com/v3/resources/customfields#customfields.get}
* @memberof GetResponse#
* @method customFields#getCustomField
* @param {string} customFieldId custom field's id obtained via {@link GetResponse#customFields#getCustomFields getCustomFields} method
* @param {array|string} fields list of fields that should be present in the returned object(s). Id is always returned
* @returns {object} custom field object
*/
methods.getCustomField = function (customFieldId, fields) {
return self.get('custom-fields/' + customFieldId, {
fields: fields
});
}
/**
* @description creates a new custom field
* @see {@link https://apidocs.getresponse.com/v3/resources/customfields#customfields.create}
* @memberof GetResponse#
* @method customFields#createCustomField
* @param {object} customField object with custom field settings (see GR API docs site for more info)
* @returns {object} newly created custom field object
*/
methods.createCustomField = function (customField) {
return self.post('custom-fields', customField);
}
/**
* @description updates values and/or visibility of a custom field (it's not possible to update its type, format or name after creation)
* @see {@link https://apidocs.getresponse.com/v3/resources/customfields#customfields.update}
* @memberof GetResponse#
* @method customFields#updateCustomField
* @param {string} customFieldId custom field's id obtained via {@link GetResponse#customFields#getCustomFields getCustomFields} method
* @param {object} customFieldSettings
* @returns {object} updated custom field object
*/
methods.updateCustomField = function (customFieldId, customFieldSettings) {
return self.post('custom-fields/' + customFieldId, customFieldSettings);
}
/**
* @description delete a custom field
* @see {@link https://apidocs.getresponse.com/v3/resources/customfields#customfields.delete}
* @memberof GetResponse#
* @method customFields#deleteCustomField
* @param {string} customFieldId custom field's id obtained via {@link GetResponse#customFields#getCustomFields getCustomFields} method
*/
methods.deleteCustomField = function (customFieldId) {
return self.remove('custom-fields/' + customFieldId);
}
/**
* @memberof GetResponse#
* @namespace tags
*/
/**
* @description gets list of available tags
* @see {@link https://apidocs.getresponse.com/v3/resources/tags#tags.get.all}
* @memberof GetResponse#
* @method tags#getTags
* @param {object|string} parameters query parameters set as object or query string
* @returns {array} list of tag objects
*/
methods.getTags = function (parameters) {
return self.get('tags', parameters);
}
/**
* @description gets info about one tag
* @see {@link https://apidocs.getresponse.com/v3/resources/tags#tags.get}
* @memberof GetResponse#
* @method tags#getTag
* @param {string} tagId tag's id obtained via {@link GetResponse#tags#getTags getTags} method
* @param {object|string} parameters
* @returns {object} tag object
*/
methods.getTag = function (tagId, parameters) {
return self.get('tags/' + tagId, parameters);
}
/**
* @description create a new tag; right now it's only possible to set its name and nothing more
* @see {@link https://apidocs.getresponse.com/v3/resources/tags#tags.post}
* @memberof GetResponse#
* @method tags#createTag
* @param {string} tagName name of the new tag