This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailchimp.js
3208 lines (2793 loc) · 179 KB
/
mailchimp.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
'use strict';
(function() {
var Campaigns, Conversations, Ecomm, Folders, Gallery, Goal, Helper, Lists, Mobile, Neapolitan, OPTS, Reports, Templates, Users, Vip, https;
https = require('https');
OPTS = {
host: 'api.mailchimp.com',
port: 443,
prefix: '/2.0/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'MailChimp-Node/2.0.7'
}
};
exports.Mailchimp = (function() {
function Mailchimp(apikey, debug) {
this.apikey = apikey !== null ? apikey : null;
this.debug = debug !== null ? debug : false;
this.folders = new Folders(this);
this.templates = new Templates(this);
this.users = new Users(this);
this.helper = new Helper(this);
this.mobile = new Mobile(this);
this.conversations = new Conversations(this);
this.ecomm = new Ecomm(this);
this.neapolitan = new Neapolitan(this);
this.lists = new Lists(this);
this.campaigns = new Campaigns(this);
this.vip = new Vip(this);
this.reports = new Reports(this);
this.gallery = new Gallery(this);
this.goal = new Goal(this);
if (this.apikey === null) {
this.apikey = process.env.MAILCHIMP_APIKEY;
}
}
Mailchimp.prototype.call = function(uri, params, onresult, onerror) {
var dc, parts, pieces, req;
if (params === null) {
params = {};
}
params.apikey = this.apikey;
pieces = OPTS.host.split('.');
if (pieces.length === 3) {
dc = 'us1';
parts = params.apikey.split('-');
if (parts.length === 2) {
dc = parts[1];
}
OPTS.host = dc + '.' + OPTS.host;
} else if (pieces.length === 4) {
// We already have an OPTS.host prefixed by a dc (datacenter) like us7.api.mailchimp.com
// ensure that it is the correct dc
dc = pieces[0];
parts = params.apikey.split('-');
if (parts.length === 2) {
dc = parts[1];
}
pieces[0] = dc;
OPTS.host = pieces.join('.');
}
params = new Buffer(JSON.stringify(params), 'utf8');
if (this.debug) {
//if (true) {
console.log(this.apikey, dc, parts, pieces);
console.log('Mailchimp: Opening request to https://' + OPTS.host + OPTS.prefix + uri + '.json');
}
OPTS.path = '' + OPTS.prefix + uri + '.json';
OPTS.headers['Content-Length'] = params.length;
req = https.request(OPTS, (function(_this) {
return function(res) {
var json;
res.setEncoding('utf8');
json = '';
res.on('data', function(d) {
return json += d;
});
return res.on('end', function() {
var e;
try {
json = JSON.parse(json);
} catch (_error) {
e = _error;
json = {
status: 'error',
name: 'GeneralError',
error: e
};
}
if (json === null) {
json = {
status: 'error',
name: 'GeneralError',
error: 'An unexpected error occurred'
};
}
if (res.statusCode !== 200) {
if (onerror) {
return onerror(json);
} else {
return _this.onerror(json);
}
} else {
if (onresult) {
return onresult(json);
}
}
});
};
})(this));
req.write(params);
req.end();
req.on('error', (function(_this) {
return function(e) {
if (onerror) {
return onerror(e);
} else {
return _this.onerror({
status: 'error',
name: 'GeneralError',
error: e
});
}
};
})(this));
return null;
};
Mailchimp.prototype.onerror = function(err) {
throw {
name: err.name,
error: err.error,
toString: function() {
return '' + err.name + ': ' + err.error;
}
};
};
Mailchimp.prototype.parseArgs = function(params, onsuccess, onerror) {
var _ref;
if (typeof params !== 'function') {
return [params, onsuccess, onerror];
}
return _ref = [{}, params, onsuccess], params = _ref[0], onsuccess = _ref[1], onerror = _ref[2], _ref;
};
return Mailchimp;
})();
Folders = (function() {
function Folders(master) {
this.master = master;
}
/*
Add a new folder to file campaigns, autoresponders, or templates in
@param {Object} params the hash of the parameters to pass to the request
@option params {String} name a unique name for a folder (max 100 bytes)
@option params {String} type the type of folder to create - one of "campaign", "autoresponder", or "template".
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Folders.prototype.add = function(params, onsuccess, onerror) {
var _ref;
if (params === null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('folders/add', params, onsuccess, onerror);
};
/*
Delete a campaign, autoresponder, or template folder. Note that this will simply make whatever was in the folder appear unfiled, no other data
is removed
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} fid the folder id to delete - retrieve from folders/list()
@option params {String} type the type of folder to delete - either "campaign", "autoresponder", or "template"
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Folders.prototype.del = function(params, onsuccess, onerror) {
var _ref;
if (params === null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('folders/del', params, onsuccess, onerror);
};
/*
List all the folders of a certain type
@param {Object} params the hash of the parameters to pass to the request
@option params {String} type the type of folders to return "campaign", "autoresponder", or "template"
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Folders.prototype.list = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('folders/list', params, onsuccess, onerror);
};
/*
Update the name of a folder for campaigns, autoresponders, or templates
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} fid the folder id to update - retrieve from folders/list()
@option params {String} name a new, unique name for the folder (max 100 bytes)
@option params {String} type the type of folder to update - one of "campaign", "autoresponder", or "template".
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Folders.prototype.update = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('folders/update', params, onsuccess, onerror);
};
return Folders;
})();
Templates = (function() {
function Templates(master) {
this.master = master;
}
/*
Create a new user template, <strong>NOT</strong> campaign content. These templates can then be applied while creating campaigns.
@param {Object} params the hash of the parameters to pass to the request
@option params {String} name the name for the template - names must be unique and a max of 50 bytes
@option params {String} html a string specifying the entire template to be created. This is <strong>NOT</strong> campaign content. They are intended to utilize our <a href="http://www.mailchimp.com/resources/email-template-language/" target="_blank">template language</a>.
@option params {Int} folder_id the folder to put this template in.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.add = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["folder_id"] == null) {
params["folder_id"] = null;
}
return this.master.call('templates/add', params, onsuccess, onerror);
};
/*
Delete (deactivate) a user template
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} template_id the id of the user template to delete
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.del = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('templates/del', params, onsuccess, onerror);
};
/*
Pull details for a specific template to help support editing
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} template_id the template id - get from templates/list()
@option params {String} type optional the template type to load - one of 'user', 'gallery', 'base', defaults to user.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.info = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["type"] == null) {
params["type"] = 'user';
}
return this.master.call('templates/info', params, onsuccess, onerror);
};
/*
Retrieve various templates available in the system, allowing some thing similar to our template gallery to be created.
@param {Object} params the hash of the parameters to pass to the request
@option params {Struct} types optional the types of templates to return
- user {Boolean} Custom templates for this user account. Defaults to true.
- gallery {Boolean} Templates from our Gallery. Note that some templates that require extra configuration are withheld. (eg, the Etsy template). Defaults to false.
- base {Boolean} Our "start from scratch" extremely basic templates. Defaults to false. As of the 9.0 update, "base" templates are no longer available via the API because they are now all saved Drag & Drop templates.
@option params {Struct} filters optional options to control how inactive templates are returned, if at all
- category {String} optional for Gallery templates only, limit to a specific template category
- folder_id {String} user templates, limit to this folder_id
- include_inactive {Boolean} user templates are not deleted, only set inactive. defaults to false.
- inactive_only {Boolean} only include inactive user templates. defaults to false.
- include_drag_and_drop {Boolean} Include templates created and saved using the new Drag & Drop editor. <strong>Note:</strong> You will not be able to edit or create new drag & drop templates via this API. This is useful only for creating a new campaign based on a drag & drop template.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.list = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["types"] == null) {
params["types"] = [];
}
if (params["filters"] == null) {
params["filters"] = [];
}
return this.master.call('templates/list', params, onsuccess, onerror);
};
/*
Undelete (reactivate) a user template
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} template_id the id of the user template to reactivate
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.undel = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('templates/undel', params, onsuccess, onerror);
};
/*
Replace the content of a user template, <strong>NOT</strong> campaign content.
@param {Object} params the hash of the parameters to pass to the request
@option params {Int} template_id the id of the user template to update
@option params {Struct} values the values to updates - while both are optional, at least one should be provided. Both can be updated at the same time.
- name {String} the name for the template - names must be unique and a max of 50 bytes
- html {String} a string specifying the entire template to be created. This is <strong>NOT</strong> campaign content. They are intended to utilize our <a href="http://www.mailchimp.com/resources/email-template-language/" target="_blank">template language</a>.
- folder_id {Int} the folder to put this template in - 0 or a blank values will remove it from a folder.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Templates.prototype.update = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('templates/update', params, onsuccess, onerror);
};
return Templates;
})();
Users = (function() {
function Users(master) {
this.master = master;
}
/*
Invite a user to your account
@param {Object} params the hash of the parameters to pass to the request
@option params {String} email A valid email address to send the invitation to
@option params {String} role the role to assign to the user - one of viewer, author, manager, admin. defaults to viewer. More details <a href="http://kb.mailchimp.com/article/can-we-have-multiple-users-on-our-account-with-limited-access" target="_blank">here</a>
@option params {String} msg an optional message to include. Plain text any HTML tags will be stripped.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.invite = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["role"] == null) {
params["role"] = 'viewer';
}
if (params["msg"] == null) {
params["msg"] = '';
}
return this.master.call('users/invite', params, onsuccess, onerror);
};
/*
Resend an invite a user to your account. Note, if the same address has been invited multiple times, this will simpy re-send the most recent invite
@param {Object} params the hash of the parameters to pass to the request
@option params {String} email A valid email address to resend an invitation to
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.inviteResend = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/invite-resend', params, onsuccess, onerror);
};
/*
Revoke an invitation sent to a user to your account. Note, if the same address has been invited multiple times, this will simpy revoke the most recent invite
@param {Object} params the hash of the parameters to pass to the request
@option params {String} email A valid email address to send the invitation to
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.inviteRevoke = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/invite-revoke', params, onsuccess, onerror);
};
/*
Retrieve the list of pending users invitations have been sent for.
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.invites = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/invites', params, onsuccess, onerror);
};
/*
Revoke access for a specified login
@param {Object} params the hash of the parameters to pass to the request
@option params {String} username The username of the login to revoke access of
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.loginRevoke = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/login-revoke', params, onsuccess, onerror);
};
/*
Retrieve the list of active logins.
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.logins = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/logins', params, onsuccess, onerror);
};
/*
Retrieve the profile for the login owning the provided API Key
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Users.prototype.profile = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('users/profile', params, onsuccess, onerror);
};
return Users;
})();
Helper = (function() {
function Helper(master) {
this.master = master;
}
/*
Retrieve lots of account information including payments made, plan info, some account stats, installed modules,
contact info, and more. No private information like Credit Card numbers is available.
@param {Object} params the hash of the parameters to pass to the request
@option params {Array} exclude defaults to nothing for backwards compatibility. Allows controlling which extra arrays are returned since they can slow down calls. Valid keys are "modules", "orders", "rewards-credits", "rewards-inspections", "rewards-referrals", "rewards-applied", "integrations". Hint: "rewards-referrals" is typically the culprit. To avoid confusion, if data is excluded, the corresponding key <strong>will not be returned at all</strong>.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.accountDetails = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["exclude"] == null) {
params["exclude"] = [];
}
return this.master.call('helper/account-details', params, onsuccess, onerror);
};
/*
Retrieve minimal data for all Campaigns a member was sent
@param {Object} params the hash of the parameters to pass to the request
@option params {Struct} email a struct with one fo the following keys - failing to provide anything will produce an error relating to the email address
- email {String} an email address
- euid {String} the unique id for an email address (not list related) - the email "id" returned from listMemberInfo, Webhooks, Campaigns, etc.
- leid {String} the list email id (previously called web_id) for a list-member-info type call. this doesn't change when the email address changes
@option params {Struct} options optional extra options to modify the returned data.
- list_id {String} optional A list_id to limit the campaigns to
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.campaignsForEmail = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["options"] == null) {
params["options"] = null;
}
return this.master.call('helper/campaigns-for-email', params, onsuccess, onerror);
};
/*
Return the current Chimp Chatter messages for an account.
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.chimpChatter = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('helper/chimp-chatter', params, onsuccess, onerror);
};
/*
Have HTML content auto-converted to a text-only format. You can send: plain HTML, an existing Campaign Id, or an existing Template Id. Note that this will <strong>not</strong> save anything to or update any of your lists, campaigns, or templates.
It's also not just Lynx and is very fine tuned for our template layouts - your mileage may vary.
@param {Object} params the hash of the parameters to pass to the request
@option params {String} type The type of content to parse. Must be one of: "html", "url", "cid" (Campaign Id), "user_template_id", "base_template_id", "gallery_template_id"
@option params {Struct} content The content to use. The key names should be the same as type and while listed as optional, may cause errors if the content is obviously required (ie, html)
- html {String} optional a single string value,
- cid {String} a valid Campaign Id
- user_template_id {String} the id of a user template
- base_template_id {String} the id of a built in base/basic template
- gallery_template_id {String} the id of a built in gallery template
- url {String} a valid & public URL to pull html content from
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.generateText = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('helper/generate-text', params, onsuccess, onerror);
};
/*
Send your HTML content to have the CSS inlined and optionally remove the original styles.
@param {Object} params the hash of the parameters to pass to the request
@option params {String} html Your HTML content
@option params {Bool} strip_css optional Whether you want the CSS <style> tags stripped from the returned document. Defaults to false.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.inlineCss = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["strip_css"] == null) {
params["strip_css"] = false;
}
return this.master.call('helper/inline-css', params, onsuccess, onerror);
};
/*
Retrieve minimal List data for all lists a member is subscribed to.
@param {Object} params the hash of the parameters to pass to the request
@option params {Struct} email a struct with one fo the following keys - failing to provide anything will produce an error relating to the email address
- email {String} an email address
- euid {String} the unique id for an email address (not list related) - the email "id" returned from listMemberInfo, Webhooks, Campaigns, etc.
- leid {String} the list email id (previously called web_id) for a list-member-info type call. this doesn't change when the email address changes
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.listsForEmail = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('helper/lists-for-email', params, onsuccess, onerror);
};
/*
"Ping" the MailChimp API - a simple method you can call that will return a constant value as long as everything is good. Note
than unlike most all of our methods, we don't throw an Exception if we are having issues. You will simply receive a different
string back that will explain our view on what is going on.
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.ping = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('helper/ping', params, onsuccess, onerror);
};
/*
Search all campaigns for the specified query terms
@param {Object} params the hash of the parameters to pass to the request
@option params {String} query terms to search on
@option params {Int} offset optional the paging offset to use if more than 100 records match
@option params {String} snip_start optional by default clear text is returned. To have the match highlighted with something (like a strong HTML tag), <strong>both</strong> this and "snip_end" must be passed. You're on your own to not break the tags - 25 character max.
@option params {String} snip_end optional see "snip_start" above.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.searchCampaigns = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["offset"] == null) {
params["offset"] = 0;
}
if (params["snip_start"] == null) {
params["snip_start"] = null;
}
if (params["snip_end"] == null) {
params["snip_end"] = null;
}
return this.master.call('helper/search-campaigns', params, onsuccess, onerror);
};
/*
Search account wide or on a specific list using the specified query terms
@param {Object} params the hash of the parameters to pass to the request
@option params {String} query terms to search on, <a href="http://kb.mailchimp.com/article/i-cant-find-a-recipient-on-my-list" target="_blank">just like you do in the app</a>
@option params {String} id optional the list id to limit the search to. Get by calling lists/list()
@option params {Int} offset optional the paging offset to use if more than 100 records match
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.searchMembers = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["id"] == null) {
params["id"] = null;
}
if (params["offset"] == null) {
params["offset"] = 0;
}
return this.master.call('helper/search-members', params, onsuccess, onerror);
};
/*
Retrieve all domain verification records for an account
@param {Object} params the hash of the parameters to pass to the request
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Helper.prototype.verifiedDomains = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('helper/verified-domains', params, onsuccess, onerror);
};
return Helper;
})();
Mobile = (function() {
function Mobile(master) {
this.master = master;
}
return Mobile;
})();
Conversations = (function() {
function Conversations(master) {
this.master = master;
}
/*
Retrieve conversation metadata, includes message data for the most recent message in the conversation
@param {Object} params the hash of the parameters to pass to the request
@option params {String} list_id optional the list id to connect to. Get by calling lists/list()
@option params {String} leid optional The member's 'leid', as found by calling lists/member-info()
@option params {String} campaign_id the campaign id to get content for (can be gathered using campaigns/list())
@option params {Int} start optional - control paging, start results at this offset, defaults to 0 (1st page of data)
@option params {Int} limit optional - control paging, number of results to return with each call, defaults to 25 (max=100)
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Conversations.prototype.list = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["list_id"] == null) {
params["list_id"] = null;
}
if (params["leid"] == null) {
params["leid"] = null;
}
if (params["campaign_id"] == null) {
params["campaign_id"] = null;
}
if (params["start"] == null) {
params["start"] = 0;
}
if (params["limit"] == null) {
params["limit"] = 25;
}
return this.master.call('conversations/list', params, onsuccess, onerror);
};
/*
Retrieve conversation messages
@param {Object} params the hash of the parameters to pass to the request
@option params {String} conversation_id the unique_id of the conversation to retrieve the messages for, can be obtained by calling converstaions/list().
@option params {Boolean} mark_as_read optional Whether or not the conversation ought to be marked as read (defaults to false).
@option params {Int} start optional - control paging, start results at this offset, defaults to 1st page of data (offset 0)
@option params {Int} limit optional - control paging, number of results to return with each call, defaults to 25 (max=100)
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Conversations.prototype.messages = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["mark_as_read"] == null) {
params["mark_as_read"] = false;
}
if (params["start"] == null) {
params["start"] = 0;
}
if (params["limit"] == null) {
params["limit"] = 25;
}
return this.master.call('conversations/messages', params, onsuccess, onerror);
};
/*
Reply to a conversation
@param {Object} params the hash of the parameters to pass to the request
@option params {String} conversation_id the unique_id of the conversation to retrieve the messages for, can be obtained by calling converstaions/list().
@option params {String} message the text of the message you want to send.
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Conversations.prototype.reply = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('conversations/reply', params, onsuccess, onerror);
};
return Conversations;
})();
Ecomm = (function() {
function Ecomm(master) {
this.master = master;
}
/*
Import Ecommerce Order Information to be used for Segmentation. This will generally be used by ecommerce package plugins
<a href="http://connect.mailchimp.com/category/ecommerce" target="_blank">provided by us or by 3rd part system developers</a>.
@param {Object} params the hash of the parameters to pass to the request
@option params {Struct} order information pertaining to the order that has completed. Use the following keys:
- id {String} the Order Id
- campaign_id {String} optional the Campaign Id to track this order against (see the "mc_cid" query string variable a campaign passes)
- email_id {String} optional (kind of) the Email Id of the subscriber we should attach this order to (see the "mc_eid" query string variable a campaign passes) - required if campaign_id is passed, otherwise either this or <strong>email</strong> is required. If both are provided, email_id takes precedence
- email {String} optional (kind of) the Email Address we should attach this order to - either this or <strong>email_id</strong> is required. If both are provided, email_id takes precedence
- total {Double} The Order Total (ie, the full amount the customer ends up paying)
- order_date {String} optional the date of the order - if this is not provided, we will default the date to now. Should be in the format of 2012-12-30
- shipping {Double} optional the total paid for Shipping Fees
- tax {Double} optional the total tax paid
- store_id {String} a unique id for the store sending the order in (32 bytes max)
- store_name {String} optional a "nice" name for the store - typically the base web address (ie, "store.mailchimp.com"). We will automatically update this if it changes (based on store_id)
- items {Array} structs for each individual line item including:
- line_num {Int} optional the line number of the item on the order. We will generate these if they are not passed
- product_id {Int} the store's internal Id for the product. Lines that do no contain this will be skipped
- sku {String} optional the store's internal SKU for the product. (max 30 bytes)
- product_name {String} the product name for the product_id associated with this item. We will auto update these as they change (based on product_id) (max 500 bytes)
- category_id {Int} (required) the store's internal Id for the (main) category associated with this product. Our testing has found this to be a "best guess" scenario
- category_name {String} (required) the category name for the category_id this product is in. Our testing has found this to be a "best guess" scenario. Our plugins walk the category heirarchy up and send "Root - SubCat1 - SubCat4", etc.
- qty {Double} optional the quantity of the item ordered - defaults to 1
- cost {Double} optional the cost of a single item (ie, not the extended cost of the line) - defaults to 0
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Ecomm.prototype.orderAdd = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('ecomm/order-add', params, onsuccess, onerror);
};
/*
Delete Ecommerce Order Information used for segmentation. This will generally be used by ecommerce package plugins
<a href="/plugins/ecomm360.phtml">that we provide</a> or by 3rd part system developers.
@param {Object} params the hash of the parameters to pass to the request
@option params {String} store_id the store id the order belongs to
@option params {String} order_id the order id (generated by the store) to delete
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Ecomm.prototype.orderDel = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
return this.master.call('ecomm/order-del', params, onsuccess, onerror);
};
/*
Retrieve the Ecommerce Orders for an account
@param {Object} params the hash of the parameters to pass to the request
@option params {String} cid if set, limit the returned orders to a particular campaign
@option params {Int} start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
@option params {Int} limit optional for large data sets, the number of results to return - defaults to 100, upper limit set at 500
@option params {String} since optional pull only messages since this time - 24 hour format in <strong>GMT</strong>, eg "2013-12-30 20:30:00"
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Ecomm.prototype.orders = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["cid"] == null) {
params["cid"] = null;
}
if (params["start"] == null) {
params["start"] = 0;
}
if (params["limit"] == null) {
params["limit"] = 100;
}
if (params["since"] == null) {
params["since"] = null;
}
return this.master.call('ecomm/orders', params, onsuccess, onerror);
};
return Ecomm;
})();
Neapolitan = (function() {
function Neapolitan(master) {
this.master = master;
}
return Neapolitan;
})();
Lists = (function() {
function Lists(master) {
this.master = master;
}
/*
Get all email addresses that complained about a campaign sent to a list
@param {Object} params the hash of the parameters to pass to the request
@option params {String} id the list id to pull abuse reports for (can be gathered using lists/list())
@option params {Int} start optional for large data sets, the page number to start at - defaults to 1st page of data (page 0)
@option params {Int} limit optional for large data sets, the number of results to return - defaults to 500, upper limit set at 1000
@option params {String} since optional pull only messages since this time - 24 hour format in <strong>GMT</strong>, eg "2013-12-30 20:30:00"
@param {Function} onsuccess an optional callback to execute when the API call is successfully made
@param {Function} onerror an optional callback to execute when the API call errors out - defaults to throwing the error as an exception
*/
Lists.prototype.abuseReports = function(params, onsuccess, onerror) {
var _ref;
if (params == null) {
params = {};
}
_ref = this.master.parseArgs(params, onsuccess, onerror), params = _ref[0], onsuccess = _ref[1], onerror = _ref[2];
if (params["start"] == null) {
params["start"] = 0;
}