This repository has been archived by the owner on May 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
sendinblue-api.js
1255 lines (1149 loc) · 60.3 KB
/
sendinblue-api.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
var restler = require('restler');
function SendinblueAPI(parameters) {
this.version = '1.0';
this.base_url = 'https://api.sendinblue.com/v2.0';
this.api_key = parameters.apiKey;
this.timeout = parameters.timeout;
}
module.exports = SendinblueAPI;
SendinblueAPI.prototype.call = function(resource, method, input, cb) {
var called_url = this.base_url + '/' + resource;
var content_type = 'application/json';
// default timeout: 30 secs
this.timeout = this.timeout !== null ? this.timeout : 30000;
if (this.timeout !== null && (this.timeout <= 0 || this.timeout > 60000)) {
throw new Error('value not allowed for timeout');
}
restler.request(called_url, {method: method, timeout: this.timeout, data: input, headers: {'api-key': this.api_key, 'content-type': content_type}})
.on('timeout', function(ms){
cb('Request timed out within '+ms+' MS', null);
})
.on('complete', function(response) {
if (response instanceof Error) {
cb("Request Failed", null);
} else {
var responseObj = JSON.parse(response);
cb(null, responseObj);
}
});
};
SendinblueAPI.prototype.get_request = function(resource, input, cb) {
this.call(resource, 'GET', input, function(err, res) {
if (err) {
return cb(err, null);
}
return cb(null, res);
});
};
SendinblueAPI.prototype.post_request = function(resource, input, cb) {
this.call(resource, 'POST', input, function(err, res) {
if (err) {
return cb(err, null);
}
return cb(null, res);
});
};
SendinblueAPI.prototype.put_request = function(resource, input, cb) {
this.call(resource, 'PUT', input, function(err, res) {
if (err) {
return cb(err, null);
}
return cb(null, res);
});
};
SendinblueAPI.prototype.delete_request = function(resource, input, cb) {
this.call(resource, 'DELETE', input, function(err, res) {
if (err) {
return cb(err, null);
}
return cb(null, res);
});
};
/*
Get Account.
No input required
*/
SendinblueAPI.prototype.get_account = function(data, cb) {
this.get_request('account', '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get SMTP details.
No input required
*/
SendinblueAPI.prototype.get_smtp_details = function(data, cb) {
this.get_request('account/smtpdetail', '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create Child Account.
@param {Object} data contains json object with key value pair.
@options data {String} child_email: Email address of Reseller child [Mandatory]
@options data {String} password: Password of Reseller child to login [Mandatory]
@options data {String} company_org: Name of Reseller child’s company [Mandatory]
@options data {String} first_name: First name of Reseller child [Mandatory]
@options data {String} last_name: Last name of Reseller child [Mandatory]
@options data {Array} credits: Number of email & sms credits respectively, which will be assigned to the Reseller child’s account [Optional]
- email_credit {Integer} number of email credits
- sms_credit {Integer} Number of sms credts
@options data {Array} associate_ip: Associate dedicated IPs to reseller child. You can use commas to separate multiple IPs [Optional]
*/
SendinblueAPI.prototype.create_child_account = function(data, cb) {
this.post_request('account', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update Child Account.
@param {Object} data contains json object with key value pair.
@options data {String} auth_key: 16 character authorization key of Reseller child to be modified [Mandatory]
@options data {String} company_org: Name of Reseller child’s company [Optional]
@options data {String} first_name: First name of Reseller child [Optional]
@options data {String} last_name: Last name of Reseller child [Optional]
@options data {String} password: Password of Reseller child to login [Optional]
@options data {Array} associate_ip: Associate dedicated IPs to reseller child. You can use commas to separate multiple IPs [Optional]
@options data {Array} disassociate_ip: Disassociate dedicated IPs from reseller child. You can use commas to separate multiple IPs [Optional]
*/
SendinblueAPI.prototype.update_child_account = function(data, cb) {
this.put_request('account', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete Child Account.
@param {Object} data contains json object with key value pair.
@options data {String} auth_key: 16 character authorization key of Reseller child to be deleted [Mandatory]
*/
SendinblueAPI.prototype.delete_child_account = function(data, cb) {
var auth_key = data.auth_key;
delete data.auth_key;
this.delete_request('account/' + auth_key, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get Reseller child Account.
@param {Object} data contains json object with key value pair.
@options data {String} auth_key: 16 character authorization key of Reseller child. Example : To get the details of more than one child account, use, {"key1":"abC01De2fGHI3jkL","key2":"mnO45Pq6rSTU7vWX"} [Mandatory]
*/
SendinblueAPI.prototype.get_reseller_child = function(data, cb) {
this.post_request('account/getchildv2', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Add/Remove Reseller child's Email/Sms credits.
@param {Object} data contains json object with key value pair.
@options data {String} auth_key: 16 character authorization key of Reseller child to modify credits [Mandatory]
@options data {Array} add_credit: Number of email & sms credits to be added. You can assign either email or sms credits, one at a time other will remain 0. [Mandatory: if rmv_credit is empty]
- email_credit {Integer} number of email credits
- sms_credit {Integer} Number of sms credts
@options data {Array} rmv_credit: Number of email & sms credits to be removed. You can assign either email or sms credits, one at a time other will remain 0. [Mandatory: if add_credits is empty]
- email_credit {Integer} number of email credits
- sms_credit {Integer} Number of sms credts
*/
SendinblueAPI.prototype.add_remove_child_credits = function(data, cb) {
this.post_request('account/addrmvcredit', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Send a transactional SMS.
@param {Object} data contains json object with key value pair.
@options data {String} to: The mobile number to send SMS to with country code [Mandatory]
@options data {String} from: The name of the sender. The number of characters is limited to 11 (alphanumeric format) [Mandatory]
@options data {String} text: The text of the message. The maximum characters used per SMS is 160, if used more than that, it will be counted as more than one SMS [Mandatory]
@options data {String} web_url: The web URL that can be called once the message is successfully delivered [Optional]
@options data {String} tag: The tag that you can associate with the message [Optional]
@options data {String} type: Type of message. Possible values – marketing (default) & transactional. You can use marketing for sending marketing SMS, & for sending transactional SMS, use transactional type [Optional]
*/
SendinblueAPI.prototype.send_sms = function(data, cb) {
this.post_request('sms', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create & Schedule your SMS campaigns.
@param {Object} data contains json object with key value pair.
@options data {String} name: Name of the SMS campaign [Mandatory]
@options data {String} sender: This allows you to customize the SMS sender. The number of characters is limited to 11 ( alphanumeric format ) [Optional]
@options data {String} content: Content of the message. The maximum characters used per SMS is 160, if used more than that, it will be counted as more than one SMS [Optional]
@options data {String} bat: Mobile number with the country code to send test SMS. The mobile number defined here should belong to one of your contacts in SendinBlue account and should not be blacklisted [Optional]
@options data {Array} listid: These are the list ids to which the SMS campaign is sent [Mandatory: if scheduled_date is not empty]
@options data {Array} exclude_list: These are the list ids which will be excluded from the SMS campaign [Optional]
@options data {String} scheduled_date: The day on which the SMS campaign is supposed to run [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.create_sms_campaign = function(data, cb) {
this.post_request('sms', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update your SMS campaigns.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of the SMS campaign [Mandatory]
@options data {String} name: Name of the SMS campaign [Optional]
@options data {String} sender: This allows you to customize the SMS sender. The number of characters is limited to 11 ( alphanumeric format ) [Optional]
@options data {String} content: Content of the message. The maximum characters used per SMS is 160, if used more than that, it will be counted as more than one SMS [Optional]
@options data {String} bat: Mobile number with the country code to send test SMS. The mobile number defined here should belong to one of your contacts in SendinBlue account and should not be blacklisted [Optional]
@options data {Array} listid: hese are the list ids to which the SMS campaign is sent [Mandatory: if scheduled_date is not empty]
@options data {Array} exclude_list: These are the list ids which will be excluded from the SMS campaign [Optional]
@options data {String} scheduled_date: The day on which the SMS campaign is supposed to run [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.update_sms_campaign = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('sms/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Send a Test SMS.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of the SMS campaign [Mandatory]
@options data {String} to: Mobile number with the country code to send test SMS. The mobile number defined here should belong to one of your contacts in SendinBlue account and should not be blacklisted [Mandatory]
*/
SendinblueAPI.prototype.send_bat_sms = function(data, cb) {
var id = data.id;
delete data.id;
this.get_request('sms/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get all campaigns detail.
@param {Object} data contains json object with key value pair.
@options data {String} type: Type of campaign. Possible values – classic, trigger, sms, template ( case sensitive ) [Optional]
@options data {String} status: Status of campaign. Possible values – draft, sent, archive, queued, suspended, in_process, temp_active, temp_inactive ( case sensitive ) [Optional]
@options data {Integer} page: Maximum number of records per request is 500, if there are more than 500 campaigns then you can use this parameter to get next 500 results [Optional]
@options data {Integer} page_limit: This should be a valid number between 1-1000. If page limit is kept empty or >1000, default is 500 [Optional]
*/
SendinblueAPI.prototype.get_campaigns_v2 = function(data, cb) {
this.get_request('campaign/detailsv2', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get a particular campaign detail.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Unique Id of the campaign [Mandatory]
*/
SendinblueAPI.prototype.get_campaign_v2 = function(data, cb) {
var id = data.id;
delete data.id;
this.get_request('campaign/' + id + '/detailsv2', '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create and Schedule your campaigns. It returns the ID of the created campaign.
@param {Object} data contains json object with key value pair.
@options data {String} category: Tag name of the campaign [Optional]
@options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} name: Name of the campaign [Mandatory]
@options data {String} bat: Email address for test mail [Optional]
@options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Mandatory: if html_url is empty]
@options data {String} html_url: Url which content is the body of content [Mandatory: if html_content is empty]
@options data {Array} listid: These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty]
@options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional]
@options data {String} subject: Subject of the campaign [Mandatory]
@options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} reply_to: The reply to email in the campaign emails [Optional]
@options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM] To use the contact attributes here, these should already exist in SendinBlue account [Optional]
@options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional]
@options data {String} attachment_url: Provide the absolute url of the attachment [Optional]
@options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional]
@options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.create_campaign = function(data, cb) {
this.post_request('campaign', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete your campaigns.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of campaign to be deleted [Mandatory]
*/
SendinblueAPI.prototype.delete_campaign = function(data, cb) {
var id = data.id;
delete data.id;
this.delete_request('campaign/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update your campaign.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of campaign to be modified [Mandatory]
@options data {String} category: Tag name of the campaign [Optional]
@options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} name: Name of the campaign [Optional]
@options data {String} bat: Email address for test mail [Optional]
@options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Optional]
@options data {String} html_url: Url which content is the body of content [Optional]
@options data {Array} listid These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty]
@options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional]
@options data {String} subject: Subject of the campaign.
@options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} reply_to: The reply to email in the campaign emails [Optional]
@options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional]
@options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional]
@options data {String} attachment_url: Provide the absolute url of the attachment [Optional]
@options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional]
@options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.update_campaign = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('campaign/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update the Campaign status.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of campaign to update its status [Mandatory]
@options data {String} status: Types of status. Possible values – suspended, archive, darchive, sent, queued, replicate and replicate_template ( case sensitive ) [Mandatory]
*/
SendinblueAPI.prototype.update_campaign_status = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('campaign/' + id + '/updatecampstatus', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Send report of Sent and Archived campaign.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of campaign to send its report [Mandatory]
@options data {String} lang: Language of email content. Possible values – fr (default), en, es, it & pt [Optional]
@options data {String} email_subject: Message subject [Mandatory]
@options data {Array} email_to: Email address of the recipient(s). Example: "[email protected]". You can use commas to separate multiple recipients [Mandatory]
@options data {String} email_content_type: Body of the message in text/HTML version. Possible values – text & html [Mandatory]
@options data {Array} email_bcc: Same as email_to but for Bcc [Optional]
@options data {Array} email_cc: Same as email_to but for Cc [Optional]
@options data {String} email_body: Body of the message [Mandatory]
*/
SendinblueAPI.prototype.campaign_report_email = function(data, cb) {
var id = data.id;
delete data.id;
this.post_request('campaign/' + id + '/report', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Export the recipients of a specified campaign.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of campaign to export its recipients [Mandatory]
@options data {String} notify_url: URL that will be called once the export process is finished [Mandatory]
@options data {String} type: Type of recipients. Possible values – all, non_clicker, non_opener, clicker, opener, soft_bounces, hard_bounces & unsubscribes [Mandatory]
*/
SendinblueAPI.prototype.campaign_recipients_export = function(data, cb) {
var id = data.id;
delete data.id;
this.post_request('campaign/' + id + '/recipients', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Send a Test Campaign.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of the campaign [Mandatory]
@options data {Array} emails: Email address of recipient(s) existing in the one of the lists & should not be blacklisted. Example: "[email protected]". You can use commas to separate multiple recipients [Mandatory]
*/
SendinblueAPI.prototype.send_bat_email = function(data, cb) {
var id = data.id;
delete data.id;
this.post_request('campaign/' + id + '/test', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create and schedule your Trigger campaigns.
@param {Object} data contains json object with key value pair.
@options data {String} category: Tag name of the campaign [Optional]
@options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} trigger_name: Name of the campaign [Mandatory]
@options data {String} bat: Email address for test mail [Optional]
@options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Mandatory: if html_url is empty]
@options data {String} html_url: Url which content is the body of content [Mandatory: if html_content is empty]
@options data {Array} listid: These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty]
@options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional]
@options data {String} subject: Subject of the campaign [Mandatory]
@options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} reply_to: The reply to email in the campaign emails [Optional]
@options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional]
@options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional]
@options data {Integer} recurring: Type of trigger campaign. Possible values = 0 (default) & 1. recurring = 0 means contact can receive the same Trigger campaign only once, & recurring = 1 means contact can receive the same Trigger campaign several times [Optional]
@options data {String} attachment_url: Provide the absolute url of the attachment [Optional]
@options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional]
@options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.create_trigger_campaign = function(data, cb) {
this.post_request('campaign', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update and schedule your Trigger campaigns.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of Trigger campaign to be modified [Mandatory]
@options data {String} category: Tag name of the campaign [Optional]
@options data {String} from_name: Sender name from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} trigger_name: Name of the campaign [Mandatory]
@options data {String} bat Email address for test mail [Optional]
@options data {String} html_content: Body of the content. The HTML content field must have more than 10 characters [Mandatory: if html_url is empty]
@options data {String} html_url: Url which content is the body of content [Mandatory: if html_content is empty]
@options data {Array} listid: These are the lists to which the campaign has been sent [Mandatory: if scheduled_date is not empty]
@options data {String} scheduled_date: The day on which the campaign is supposed to run[Optional]
@options data {String} subject: Subject of the campaign [Mandatory]
@options data {String} from_email: Sender email from which the campaign emails are sent [Mandatory: for Dedicated IP clients, please make sure that the sender details are defined here, and in case of no sender, you can add them also via API & for Shared IP clients, if sender exists]
@options data {String} reply_to: The reply to email in the campaign emails [Optional]
@options data {String} to_field: This is to personalize the «To» Field. If you want to include the first name and last name of your recipient, add [PRENOM] [NOM]. To use the contact attributes here, these should already exist in SendinBlue account [Optional]
@options data {Array} exclude_list: These are the lists which must be excluded from the campaign [Optional]
@options data {Integer} recurring: Type of trigger campaign. Possible values = 0 (default) & 1. recurring = 0 means contact can receive the same Trigger campaign only once, & recurring = 1 means contact can receive the same Trigger campaign several times [Optional]
@options data {String} attachment_url: Provide the absolute url of the attachment [Optional]
@options data {Integer} inline_image: Status of inline image. Possible values = 0 (default) & 1. inline_image = 0 means image can’t be embedded, & inline_image = 1 means image can be embedded, in the email [Optional]
@options data {Integer} mirror_active: Status of mirror links in campaign. Possible values = 0 & 1 (default). mirror_active = 0 means mirror links are deactivated, & mirror_active = 1 means mirror links are activated, in the campaign [Optional]
@options data {Integer} send_now: Flag to send campaign now. Possible values = 0 (default) & 1. send_now = 0 means campaign can’t be send now, & send_now = 1 means campaign ready to send now [Optional]
*/
SendinblueAPI.prototype.update_trigger_campaign = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('campaign/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get the Campaign name, subject and share link of the classic type campaigns only which are sent, for those which are not sent and the rest of campaign types like trigger, template & sms, will return an error message of share link not available.
@param {Object} data contains json object with key value pair.
@options data {Array} camp_ids: Id of campaign to get share link. You can use commas to separate multiple ids [Mandatory]
*/
SendinblueAPI.prototype.share_campaign = function(data, cb) {
this.post_request('campaign/sharelinkv2', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get all the processes information under the account.
@param {Object} data contains json object with key value pair.
@options data {Integer} page: Maximum number of records per request is 50, if there are more than 50 processes then you can use this parameter to get next 50 results [Mandatory]
@options data {Integer} page_limit: This should be a valid number between 1-50 [Mandatory]
*/
SendinblueAPI.prototype.get_processes = function(data, cb) {
this.get_request('process', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get the process information.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of process to get details [Mandatory]
*/
SendinblueAPI.prototype.get_process = function(data, cb) {
var id = data.id;
delete data.id;
this.get_request('process/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get all lists detail.
@param {Object} data contains json object with key value pair.
@options data {Integer} list_parent: This is the existing folder id & can be used to get all lists belonging to it [Optional]
@options data {Integer} page: Maximum number of records per request is 50, if there are more than 50 processes then you can use this parameter to get next 50 results [Mandatory]
@options data {Integer} page_limit: This should be a valid number between 1-50 [Mandatory]
*/
SendinblueAPI.prototype.get_lists = function(data, cb) {
this.get_request('list', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get a particular list detail.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of list to get details [Mandatory]
*/
SendinblueAPI.prototype.get_list = function(data, cb) {
var id = data.id;
delete data.id;
this.get_request('list/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create a new list.
@param {Object} data contains json object with key value pair.
@options data {String} list_name: Desired name of the list to be created [Mandatory]
@options data {Integer} list_parent: Folder ID [Mandatory]
*/
SendinblueAPI.prototype.create_list = function(data, cb) {
this.post_request('list', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete a specific list.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of list to be deleted [Mandatory]
*/
SendinblueAPI.prototype.delete_list = function(data, cb) {
var id = data.id;
delete data.id;
this.delete_request('list/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update a list.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of list to be modified [Mandatory]
@options data {String} list_name: Desired name of the list to be modified [Optional]
@options data {Integer} list_parent: Folder ID [Mandatory]
*/
SendinblueAPI.prototype.update_list = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('list/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Display details of all users for the given lists.
@param {Object} data contains json object with key value pair.
@options data {Array} listids: These are the list ids to get their data. The ids found will display records [Mandatory]
@options data {String} timestamp: This is date-time filter to fetch modified user records >= this time. Valid format Y-m-d H:i:s. Example: "2015-05-22 14:30:00" [Optional]
@options data {Integer} page: Maximum number of records per request is 500, if in your list there are more than 500 users then you can use this parameter to get next 500 results [Optional]
@options data {Integer} page_limit: This should be a valid number between 1-500 [Optional]
*/
SendinblueAPI.prototype.display_list_users = function(data, cb) {
this.post_request('list/display', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Add already existing users in the SendinBlue contacts to the list.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of list to link users in it [Mandatory]
@options data {Array} users: Email address of the already existing user(s) in the SendinBlue contacts. Example: "[email protected]". You can use commas to separate multiple users [Mandatory]
*/
SendinblueAPI.prototype.add_users_list = function(data, cb) {
var id = data.id;
delete data.id;
this.post_request('list/' + id + '/users', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete already existing users in the SendinBlue contacts from the list.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of list to unlink users from it [Mandatory]
@options data {Array} users: Email address of the already existing user(s) in the SendinBlue contacts to be modified. Example: "[email protected]". You can use commas to separate multiple users [Mandatory]
*/
SendinblueAPI.prototype.delete_users_list = function(data, cb) {
var id = data.id;
delete data.id;
this.delete_request('list/' + id + '/delusers', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Send Transactional Email.
@param {Object} data contains json object with key value pair.
@options data {Array} to: Email address of the recipient(s). It should be sent as an associative array. Example: array("[email protected]"=>"to whom"). You can use commas to separate multiple recipients [Mandatory]
@options data {String} subject: Message subject [Mandatory]
@options data {Array} from Email address for From header. It should be sent as an array. Example: array("[email protected]","from email") [Mandatory]
@options data {String} html: Body of the message. (HTML version) [Mandatory]. To send inline images, use <img src="{YourFileName.Extension}" alt="image" border="0" >, the 'src' attribute value inside {} (curly braces) should be same as the filename used in 'inline_image' parameter
@options data {String} text: Body of the message. (text version) [Optional]
@options data {Array} cc: Same as to but for Cc. Example: array("[email protected]","cc whom") [Optional]
@options data {Array} bcc: Same as to but for Bcc. Example: array("[email protected]","bcc whom") [Optional]
@options data {Array} replyto: Same as from but for Reply To. Example: array("[email protected]","from email") [Optional]
@options data {Array} attachment: Provide the absolute url of the attachment/s. Possible extension values = gif, png, bmp, cgm, jpg, jpeg, txt, css, shtml, html, htm, csv, zip, pdf, xml, doc, xls, ppt, tar and ez. To send attachment/s generated on the fly you have to pass your attachment/s filename & its base64 encoded chunk data as an associative array. Example: array("YourFileName.Extension"=>"Base64EncodedChunkData"). You can use commas to separate multiple attachments [Optional]
@options data {Array} headers: The headers will be sent along with the mail headers in original email. Example: array("Content-Type"=>"text/html; charset=iso-8859-1"). You can use commas to separate multiple headers [Optional]
@options data {Array} inline_image: Pass your inline image/s filename & its base64 encoded chunk data as an associative array. Possible extension values = gif, png, bmp, cgm, jpg and jpeg. Example: array("YourFileName.Extension"=>"Base64EncodedChunkData"). You can use commas to separate multiple inline images [Optional]
*/
SendinblueAPI.prototype.send_email = function(data, cb) {
this.post_request('email', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
To retrieve details of all webhooks.
@param {Object} data contains json object with key value pair.
@options data {String} is_plat: Flag to get webhooks. Possible values – 0 & 1. Example: to get Transactional webhooks, use $is_plat=0, to get Marketing webhooks, use $is_plat=1, & to get all webhooks, use $is_plat="" [Optional]
*/
SendinblueAPI.prototype.get_webhooks = function(data, cb) {
this.get_request('webhook', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
To retrieve details of all webhooks.
@param {Object} data contains json object with key value pair.
@options data {String} is_plat: Flag to get webhooks. Possible values – 0 & 1. Example: to get Transactional webhooks, use $is_plat=0, to get Marketing webhooks, use $is_plat=1, & to get all webhooks, use $is_plat="" [Optional]
*/
SendinblueAPI.prototype.get_webhook = function(data, cb) {
var id = data.id;
delete data.id;
this.get_request('webhook/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create a Webhook.
@param {Object} data contains json object with key value pair.
@options data {String} url: URL that will be triggered by a webhook [Mandatory]
@options data {String} description: Webook description [Optional]
@options data {Array} events: Set of events. You can use commas to separate multiple events. Possible values for Transcational webhook – request, delivered, hard_bounce, soft_bounce, blocked, spam, invalid_email, deferred, click, & opened and Possible Values for Marketing webhook – spam, opened, click, hard_bounce, unsubscribe, soft_bounce & list_addition ( case sensitive ) [Mandatory]
@options data {Integer} is_plat: Flag to create webhook type. Possible values – 0 (default) & 1. Example: to create Transactional webhooks, use $is_plat=0, & to create Marketing webhooks, use $is_plat=1 [Optional]
*/
SendinblueAPI.prototype.create_webhook = function(data, cb) {
this.post_request('webhook', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete a webhook.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of webhook to be deleted [Mandatory]
*/
SendinblueAPI.prototype.delete_webhook = function(data, cb) {
var id = data.id;
delete data.id;
this.delete_request('webhook/' + id, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Update a webhook.
@param {Object} data contains json object with key value pair.
@options data {Integer} id: Id of webhook to be modified [Mandatory]
@options data {String} url: URL that will be triggered by a webhook [Mandatory]
@options data {String} description: Webook description [Optional]
@options data {Array} events: Set of events. You can use commas to separate multiple events. Possible values for Transcational webhook – request, delivered, hard_bounce, soft_bounce, blocked, spam, invalid_email, deferred, click, & opened and Possible Values for Marketing webhook – spam, opened, click, hard_bounce, unsubscribe, soft_bounce & list_addition ( case sensitive ) [Mandatory]
*/
SendinblueAPI.prototype.update_webhook = function(data, cb) {
var id = data.id;
delete data.id;
this.put_request('webhook/' + id, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Aggregate / date-wise report of the SendinBlue SMTP account.
@param {Object} data contains json object with key value pair.
@options data {Integer} aggregate: This is used to indicate, you are interested in all-time totals. Possible values – 0 & 1. aggregate = 0 means it will not aggregate records, and will show stats per day/date wise [Optional]
@options data {String} start_date: The start date to look up statistics. Date must be in YYYY-MM-DD format and should be before the end_date [Optional]
@options data {String} end_date: The end date to look up statistics. Date must be in YYYY-MM-DD format and should be after the start_date [Optional]
@options data {Integer} days: Number of days in the past to include statistics ( Includes today ). It must be an integer greater than 0 [Optional]
@options data {String} tag: The tag you will specify to retrieve detailed stats. It must be an existing tag that has statistics [Optional]
*/
SendinblueAPI.prototype.get_statistics = function(data, cb) {
this.post_request('statistics', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get Access a specific user Information.
@param {Object} data contains json object with key value pair.
@options data {String} email: Email address of the already existing user in the SendinBlue contacts [Mandatory]
*/
SendinblueAPI.prototype.get_user = function(data, cb) {
var email = data.email;
delete data.email;
this.get_request('user/' + encodeURIComponent(email), '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Unlink existing user from all lists.
@param {Object} data contains json object with key value pair.
@options data {String} email: Email address of the already existing user in the SendinBlue contacts to be unlinked from all lists [Mandatory]
*/
SendinblueAPI.prototype.delete_user = function(data, cb) {
var email = data.email;
delete data.email;
this.delete_request('user/' + encodeURIComponent(email), '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Import Users Information.
@param {Object} data contains json object with key value pair.
@options data {String} url: The URL of the file to be imported. Possible file types – .txt, .csv [Mandatory: if body is empty]
@options data {String} body: The Body with csv content to be imported. Example: ‘NAME;SURNAME;EMAIL\n"Name1";"Surname1";"[email protected]"\n"Name2";"Surname2";"[email protected]"‘, where \n separates each user data. You can use semicolon to separate multiple attributes [Mandatory: if url is empty]
@options data {Array} listids: These are the list ids in which the the users will be imported [Mandatory: if name is empty]
@options data {String} notify_url: URL that will be called once the import process is finished [Optional] In notify_url, we are sending the content using POST method
@options data {String} name: This is new list name which will be created first & then users will be imported in it [Mandatory: if listids is empty]
@options data {Integer} list_parent: This is the existing folder id & can be used with name parameter to make newly created list’s desired parent [Optional]
*/
SendinblueAPI.prototype.import_users = function(data, cb) {
this.post_request('user/import', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Export Users Information.
@param {Object} data contains json object with key value pair.
@options data {String} export_attrib: The name of attribute present in your SendinBlue account. You can use commas to separate multiple attributes. Example: "EMAIL,NAME,SMS" [Optional]
@options data {String} filter: Filter can be added to export users. Example: "{\"blacklisted\":1}", will export all blacklisted users [Mandatory]
@options data {String} notify_url: URL that will be called once the export process is finished [Optional]
*/
SendinblueAPI.prototype.export_users = function(data, cb) {
this.post_request('user/export', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create a new user if an email provided as input, doesn’t exists in the contact list of your SendinBlue account, otherwise it will update the existing user.
@param {Object} data contains json object with key value pair.
@options data {String} email: Email address of the user to be created in SendinBlue contacts. Already existing email address of user in the SendinBlue contacts to be modified [Mandatory]
@options data {Array} attributes: The name of attribute present in your SendinBlue account. It should be sent as an associative array. Example: array("NAME"=>"name"). You can use commas to separate multiple attributes [Optional]
@options data {Integer} blacklisted: This is used to blacklist/ Unblacklist a user. Possible values – 0 & 1. blacklisted = 1 means user has been blacklisted [Optional]
@options data {Array} listid: The list id(s) to be linked from user [Optional]
@options data {Array} listid_unlink: The list id(s) to be unlinked from user [Optional]
@options data {Array} blacklisted_sms: This is used to blacklist/ Unblacklist a user’s SMS number. Possible values – 0 & 1. blacklisted_sms = 1 means user’s SMS number has been blacklisted [Optional]
*/
SendinblueAPI.prototype.create_update_user = function(data, cb) {
this.post_request('user/createdituser', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Access all the attributes information under the account.
No input required
*/
SendinblueAPI.prototype.get_attributes = function(data, cb) {
this.get_request('attribute', '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Access the specific type of attribute information.
@param {Object} data contains json object with key value pair.
@options data {String} type: Type of attribute. Possible values – normal, transactional, category, calculated & global [Optional]
*/
SendinblueAPI.prototype.get_attribute = function(data, cb) {
var type = data.type;
delete data.type;
this.get_request('attribute/' + type, '', function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Create an Attribute.
@param {Object} data contains json object with key value pair.
@options data {String} type: Type of attribute. Possible values – normal, transactional, category, calculated & global ( case sensitive ) [Mandatory]
@options data {Array} data: The name and data type of ‘normal’ & ‘transactional’ attribute to be created in your SendinBlue account. It should be sent as an associative array. Example: array(‘ATTRIBUTE_NAME1′ => ‘DATA_TYPE1′, ‘ATTRIBUTE_NAME2’=> ‘DATA_TYPE2′).
The name and data value of ‘category’, ‘calculated’ & ‘global’, should be sent as JSON string. Example: ‘[{ "name":"ATTRIBUTE_NAME1", "value":"Attribute_value1" }; { "name":"ATTRIBUTE_NAME2", "value":"Attribute_value2" }]’. You can use commas to separate multiple attributes [Mandatory]
*/
SendinblueAPI.prototype.create_attribute = function(data, cb) {
this.post_request('attribute', JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Delete a specific type of attribute information.
@param {Object} data contains json object with key value pair.
@options data {Integer} type: Type of attribute to be deleted [Mandatory]
*/
SendinblueAPI.prototype.delete_attribute = function(data, cb) {
var type = data.type;
delete data.type;
this.post_request('attribute/' + type, JSON.stringify(data), function(error, result) {
if (error) {
return cb(error, null);
}
return cb(null, result);
});
};
/*
Get Email Event report.
@param {Object} data contains json object with key value pair.