-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sendgrid.cfc
2050 lines (1751 loc) · 82.1 KB
/
sendgrid.cfc
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
/**
* sendgrid.cfc
* Copyright 2017-2021 Matthew Clemente, John Berquist
* Licensed under MIT (https://github.com/mjclemente/sendgrid.cfc/blob/master/LICENSE)
*/
component output="false" displayname="SendGrid.cfc" {
variables._sendgridcfc_version = '1.0.2';
public any function init(
string apiKey = '',
string emailValidationApiKey = '',
string baseUrl = "https://api.sendgrid.com/v3",
boolean forceTestMode = false,
numeric httpTimeout = 50,
boolean includeRaw = false ) {
structAppend( variables, arguments );
//map sensitive args to env variables or java system props
var secrets = {
'apiKey': 'SENDGRID_API_KEY',
'emailValidationApiKey': 'SENDGRID_EMAIL_VALIDATION_API_KEY'
};
var system = createObject( 'java', 'java.lang.System' );
for ( var key in secrets ) {
//arguments are top priority
if ( variables[ key ].len() ) continue;
//check environment variables
var envValue = system.getenv( secrets[ key ] );
if ( !isNull( envValue ) && envValue.len() ) {
variables[ key ] = envValue;
continue;
}
//check java system properties
var propValue = system.getProperty( secrets[ key ] );
if ( !isNull( propValue ) && propValue.len() ) {
variables[ key ] = propValue;
}
}
variables.utcBaseDate = dateAdd( "l", createDate( 1970,1,1 ).getTime() * -1, createDate( 1970,1,1 ) );
return this;
}
/**
* Mail Send
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html
*/
/**
* @hint Sends email, using SendGrid's REST API.
* @mail must be an instance of the `helpers.mail` component. The README provides examples of how to build and send an email
*/
public struct function sendMail( required component mail ) {
if ( variables.forceTestMode ) mail.enableSandboxMode();
return apiCall( 'POST', '/mail/send', {}, mail.build() );
}
/**
* API Keys API
* https://sendgrid.com/docs/API_Reference/Web_API_v3/API_Keys/index.html
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/retrieve-all-api-keys-belonging-to-the-authenticated-user
* @hint Retrieve all API Keys belonging to the authenticated user
* @limit limits the number of rows returned.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function listKeys( numeric limit = 0, string on_behalf_of = '' ) {
var params = {};
if ( limit ) params[ 'limit' ] = limit;
return apiCall( 'GET', "/api_keys", params, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/retrieve-an-existing-api-key
* @hint Retrieve an existing API Key
* @api_key_id is the ID of the API Key for which you are requesting information. The SendGrid docs for this endpoint explain where to find this.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getAPIKey( required string api_key_id, string on_behalf_of = '' ) {
return apiCall( 'GET', "/api_keys/#api_key_id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/create-api-keys
* @hint Creates an API key.
* @name should be the name of your new key
* @scopes refers to the individual permissions that you are giving to this API Key ( [options listed here](https://sendgrid.api-docs.io/v3.0/how-to-use-the-sendgrid-v3-api/api-authorization) )
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function createAPIKey( required string name, array scopes = ['mail.send'], string on_behalf_of = '' ) {
var body = {
'name': name,
'scopes': scopes
};
return apiCall( 'POST', '/api_keys', {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/delete-api-keys
* @hint Delete an API key
* @api_key_id is the ID of the API Key for which you are requesting information. The SendGrid docs for this endpoint explain where to find this.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function deleteAPIKey( required string api_key_id, string on_behalf_of = '' ) {
return apiCall( 'DELETE', "/api_keys/#api_key_id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/update-api-keys
* @hint Updates the name of an existing API Key.
* @api_key_id is the ID of the API Key for which you are requesting information. The SendGrid docs for this endpoint explain where to find this.
* @name is the new name for the API Key that you are updating.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateAPIKeyName( required string api_key_id, required string name, string on_behalf_of = '' ) {
var body = {
'name': name
};
return apiCall( 'PATCH', "/api_keys/#api_key_id#", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/api-keys/update-the-name-and-scopes-of-an-api-key
* @hint Updates the name and scopes of a given API key.
* @api_key_id is the ID of the API Key for which you are requesting information. The SendGrid docs for this endpoint explain where to find this.
* @scopes is optional and defaults to `mail.send`. It refers to the individual permissions that you are giving to this API Key ( [options listed here](https://sendgrid.api-docs.io/v3.0/how-to-use-the-sendgrid-v3-api/api-authorization) )
* @name is the updated name for the API Key that you are updating. It is required.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateAPIKey( required string api_key_id, required string name, array scopes = ['mail.send'], string on_behalf_of = '' ) {
var body = {
'name': name,
'scopes': scopes
};
return apiCall( 'PUT', "/api_keys/#api_key_id#", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* Subusers API
* https://sendgrid.com/docs/ui/account-and-settings/subusers/
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/list-all-subusers
* @hint Retrieve a list of all of your subusers.
* @username is the username of the subuser to return. (Optional)
* @limit limits the number of results you would like to get in each request. (Optional)
* @offset is the number of subusers to skip (Optional)
*/
public struct function listAllSubusers( string username = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
if ( len(username) ) params[ 'username' ] = username;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/subusers", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-monitor-settings-for-a-subuser
* @hint Retrieves monitor settings for a subuser.
* @subuser_name is the name of the subuser to return.
*/
public struct function getSubuserMonitorSettings( required string subuser_name ) {
return apiCall( 'GET', "/subusers/#subuser_name#/monitor" );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-subuser-reputations
* @hint Retrieves subuser reputations.
* @usernames is the name of the subuser that you are obtaining the reputation score for.
*/
public struct function getSubuserReputations( required string usernames ) {
var params = {
'usernames': usernames
};
return apiCall( 'GET', "/subusers/reputations", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-the-monthly-email-statistics-for-a-single-subuser
* @hint Retrieve the monthly email statistics for a single subuser
* @subuser_name is the name of the subuser to return.
* @date is the date the statistics were gathered in the format: YYYY-MM-DD.
*/
public struct function getSubuserMonthlyStats( required string subuser_name, required string date = '', string sort_by_metric = '', string sort_by_direction = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
if (len(date)) {
params[ 'date' ] = dateFormat(date, 'YYYY-mm-dd');
} else {
params[ 'date' ] = dateFormat(now(), 'YYYY-mm-dd');
}
if ( len(sort_by_metric) ) params[ 'sort_by_metric' ] = sort_by_metric;
if ( len(sort_by_direction) ) params[ 'sort_by_direction' ] = sort_by_direction;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/subusers/#subuser_name#/stats/monthly", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-monthly-stats-for-all-subusers
* @hint Retrieve monthly stats for all subusers
* @date is the date the statistics were gathered in the format: YYYY-MM-DD.
* @subuser is a substring search of your subusers.
*/
public struct function getSubuserMonthlyStatsAllSubusers( required string date = '', string subuser = '', string sort_by_metric = '', string sort_by_direction = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
if (len(date)) {
params[ 'date' ] = dateFormat(date, 'YYYY-mm-dd');
} else {
params[ 'date' ] = dateFormat(now(), 'YYYY-mm-dd');
}
if ( len(subuser) ) params[ 'subuser' ] = subuser;
if ( len(sort_by_metric) ) params[ 'sort_by_metric' ] = sort_by_metric;
if ( len(sort_by_direction) ) params[ 'sort_by_direction' ] = sort_by_direction;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/subusers/stats/monthly", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-the-totals-for-each-email-statistic-metric-for-all-subusers
* @hint Retrieve the totals for each email statistic metric for all subusers.
* @start_date is the starting date of the statistics to retrieve in the format YYYY-MM-DD.
* @end_date is the end date of the statistics to retrieve in the format YYYY-MM-DD. It defaults to today.
*/
public struct function getAllSubuserTotals( required string start_date, string end_date = '', string sort_by_metric = '', string sort_by_direction = '', string aggregated_by = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
params[ 'start_date' ] = start_date;
if (len(end_date)) params[ 'end_date' ] = end_date;
if (len(aggregated_by)) params[ 'aggregated_by' ] = aggregated_by;
if ( len(sort_by_metric)) params[ 'sort_by_metric' ] = sort_by_metric;
if ( len(sort_by_direction)) params[ 'sort_by_direction' ] = sort_by_direction;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/subusers/stats/sums", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/retrieve-email-statistics-for-your-subusers
* @hint Allows you to retrieve the email statistics for the given subusers.
* @subusers is the subusers you want to retrieve statistics for. You may include this parameter up to 10 times to retrieve statistics for multiple subusers.
* @start_date is the starting date of the statistics to retrieve in the format YYYY-MM-DD.
* @end_date is the end date of the statistics to retrieve in the format YYYY-MM-DD. It defaults to today.
*/
public struct function getSubuserStats( required string subusers, required string start_date, string end_date = '', string sort_by_metric = '', string sort_by_direction = '', string aggregated_by = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
params[ 'subusers' ] = subusers;
params[ 'start_date' ] = start_date;
if (len(end_date)) params[ 'end_date' ] = end_date;
if (len(aggregated_by)) params[ 'aggregated_by' ] = aggregated_by;
if ( len(sort_by_metric)) params[ 'sort_by_metric' ] = sort_by_metric;
if ( len(sort_by_direction)) params[ 'sort_by_direction' ] = sort_by_direction;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/subusers/stats", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/create-subuser
* @hint Creates a Subuser
* @username is the username for this subuser.
* @email is the email address of the subuser.
* @password is the password this subuser will use when logging into SendGrid.
* @ips are the IP addresses that should be assigned to this subuser.
*/
public struct function createSubuser( required string username, required string email, required string password, required array ips = [] ) {
var body = {
'username': username,
'email': email,
'password': password,
'ips': ips
};
return apiCall( 'POST', '/subusers', {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/delete-a-subuser
* @hint Delete a subuser
* @subuser_name is the name of the subuser to delete
*/
public struct function deleteSubuser( required string subuser_name ) {
return apiCall( 'DELETE', "/subusers/#subuser_name#" );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/subusers-api/update-ips-assigned-to-a-subuser
* @hint Update IPs assigned to a subuser
* @subuser_name is the name of the subuser to update
* @ips are the IP addresses that are assigned to the subuser.
*/
public struct function updateSubuserIPs( required string subuser_name, required array ips = [] ) {
return apiCall( 'PUT', "/subusers/#subuser_name#/ips", {}, ips );
}
/**
* Link branding
* https://sendgrid.api-docs.io/v3.0/link-branding/retrieve-all-link-branding
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/retrieve-all-link-branding
* @hint Retrieve all branded links
* @limit limits the number of rows returned.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function listBrandedLinks( numeric limit = 0, string on_behalf_of = '' ) {
var params = {};
if ( limit ) params[ 'limit' ] = limit;
return apiCall( 'GET', "/whitelabel/links", params, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/retrieve-branded-link
* @hint Retrieve a branded link
* @id is the id of the branded link you want to retrieve.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getBrandedLink( required numeric id = 0, string on_behalf_of = '' ) {
return apiCall( 'GET', "/whitelabel/links/#id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/retrieve-the-default-branded-link
* @hint Retrieve the default branded link. The default branded link is the actual URL to be used when sending messages.
* @domain is the domain to match against when finding a corresponding branded link.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getDefaultBrandedLink( string domain = '', string on_behalf_of = '' ) {
var params = {};
if ( len(domain)) params[ 'domain' ] = domain;
return apiCall( 'GET', "/whitelabel/links/default", params, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/retrieve-a-subusers-branded-link
* @hint Retrieve a subuser's branded link
* @username specifies the username of the subuser to retrieve associated branded links for.
*/
public struct function getSubuserBrandedLink( required string username = '' ) {
var params = {};
if ( len(username)) params[ 'username' ] = username;
return apiCall( 'GET', "/whitelabel/links/subuser", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/create-a-link-branding
* @hint Create a branded link
* @domain is the root domain for your subdomain that you are creating the link branding for. This should match your FROM email address.
* @subdomain is the subdomain to create the link branding for. Must be different from the subdomain you used for authenticating your domain.
* @default indicates if you want to use this link branding as the fallback, or as the default.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function createLinkBranding( required string domain, string subdomain = '', boolean default, string on_behalf_of = '' ) {
var body = {
'domain': domain
};
if( len(subdomain) ){
body['subdomain'] = subdomain;
}
if( !isNull( default ) ){
body['default'] = default;
}
return apiCall( 'POST', "/whitelabel/links", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/delete-a-branded-link
* @hint Delete a branded link
* @id is the id of the branded link you want to delete.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function deleteBrandedLink( required numeric id, string on_behalf_of = '' ) {
return apiCall( 'DELETE', "/whitelabel/links/#id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/validate-a-branded-link
* @hint Validate a branded link
* @id is the id of the branded link you want to delete.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function validateLinkBranding( required numeric id = 0, string on_behalf_of = '' ) {
return apiCall( 'POST', "/whitelabel/links/#id#/validate", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/associate-a-branded-link-with-a-subuser
* @hint Associate a branded link with a subuser
* @link_id is the id of the branded link you want to associate.
* @username is the username of the subuser account that you want to associate the branded link with.
*/
public struct function associateLinkBranding( required numeric link_id, string username = '') {
var body = {};
if( len( username ) ){
body[ 'username' ] = username;
}
return apiCall( 'POST', "/whitelabel/links/#link_id#/subuser", {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/link-branding/disassociate-link-branding-from-a-subuser
* @hint Disassociate link branding from a subuser
* @username is the username of the subuser account that you want to disassociate link branding from.
*/
public struct function disassociateBrandedLink( required string username ) {
var params = {
'username': username
};
return apiCall( 'DELETE', "/whitelabel/links/subuser", params );
}
/**
* Domain Authentication
* https://sendgrid.api-docs.io/v3.0/domain-authentication/list-all-authenticated-domains
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/list-all-authenticated-domains
* @hint List all authenticated domains
* @exclude_subusers excludes subuser domains from the result.
* @username is the username associated with an authenticated domain.
* @domain searches for authenticated domains.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function listAllDomains( numeric limit = 0, numeric offset = 0, boolean exclude_subusers = false, string username = '', string domain = '', string on_behalf_of = '' ) {
var params = {};
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
params[ 'exclude_subusers' ] = exclude_subusers;
if ( len(username) ) params[ 'username' ] = username;
if ( len(domain) ) params[ 'domain' ] = domain;
return apiCall( 'GET', "/whitelabel/domains", params, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/retrieve-a-authenticated-domain
* @hint Retrieve an authenticated domain
* @domain_id is the id of the authenticated domain you want to retrieve.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getAuthenticatedDomain( required numeric domain_id = 0, string on_behalf_of = '' ) {
return apiCall( 'GET', "/whitelabel/domains/#domain_id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/authenticate-a-domain
* @hint Authenticate a domain
* @domain should be an instance of the `helpers.domain` component. However, if you want to create and pass in the struct or json yourself, you can.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function createAuthenticatedDomain( required any domain, string on_behalf_of = '') {
var body = {};
if ( isValid( 'component', domain ) )
body = domain.build();
else
body = domain;
return apiCall( 'POST', "/whitelabel/domains", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/update-an-authenticated-domain
* @hint Update an authenticated domain
* @domain_id is the domain ID to be updated.
* @custom_spf specifies whether to use a custom SPF or allow SendGrid to manage your SPF. This option is only available to authenticated domains set up for manual security.
* @default indicates whether to use this authenticated domain as the fallback if no authenticated domains match the sender's domain.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateAuthenticatedDomain( required numeric domain_id, boolean custom_spf, boolean default, string on_behalf_of = '' ) {
var body = {};
if( !isNull( custom_spf ) ){
body['custom_spf'] = custom_spf;
}
if( !isNull( default ) ){
body['default'] = default;
}
return apiCall( 'PATCH', "/whitelabel/domains/#domain_id#", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/delete-an-authenticated-domain
* @hint Delete an authenticated domain.
* @domain_id is the id of the domain you want to delete.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function deleteAuthenticatedDomain( required numeric domain_id = 0, string on_behalf_of = '' ) {
return apiCall( 'DELETE', "/whitelabel/domains/#domain_id#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/get-the-default-authentication
* @hint Get the default authenticated domain
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getDefaultAuthenticatedDomain( string on_behalf_of = '' ) {
return apiCall( 'GET', "/whitelabel/domains/default", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/add-an-ip-to-an-authenticated-domain
* @hint Add an IP to an authenticated domain
* @domain_id is the ID of the domain to be updated.
* @ip is the IP to associate with the domain. Used for manually specifying IPs for custom SPF.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function addIPAuthenticatedDomain( required numeric domain_id, required string ip, string on_behalf_of = '' ) {
var body = {
'ip': ip
};
return apiCall( 'POST', "/whitelabel/domains/#domain_id#/ips", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/remove-an-ip-from-an-authenticated-domain
* @hint Remove an IP from an authenticated domain.
* @domain_id is the ID of the domain to delete the IP from.
* @ip is the IP to remove from the domain.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function deleteIPForAuthenticatedDomain( required numeric domain_id, required string ip, string on_behalf_of = '' ) {
return apiCall( 'DELETE', "/whitelabel/domains/#domain_id#/ips/#ip#", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/validate-a-domain-authentication
* @hint Validate a domain authentication.
* @domain_id is the ID of the domain to validate.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function validateAuthenticatedDomain( required numeric domain_id, string on_behalf_of = '' ) {
return apiCall( 'POST', "/whitelabel/domains/#domain_id#/validate", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/list-the-authenticated-domain-associated-with-the-given-user
* @hint List the authenticated domain associated with the given user.
* @username is the username for the subuser to find associated authenticated domain.
*/
public struct function listSubuserAuthenticatedDomain( required string username ) {
var params = {};
if ( len(username) ) params[ 'username' ] = username;
return apiCall( 'GET', "/whitelabel/domains/subuser", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/disassociate-an-authenticated-domain-from-a-given-user
* @hint Disassociate a authenticated domain from a given user.
* @username is the username for the subuser to disassociate from an authenticated domain.
*/
public struct function disassociateSubuserAuthenticatedDomain( required string username ) {
var params = {};
if ( len(username) ) params[ 'username' ] = username;
return apiCall( 'DELETE', "/whitelabel/domains/subuser", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/domain-authentication/associate-an-authenticated-domain-with-a-given-user
* @hint Associate a authenticated domain with a given user.
* @domain_id is the ID of the authenticated domain to associate with the subuser.
* @username is the username to associate with the authenticated domain.
*/
public struct function associateSubuserWithAuthenticatedDomain( required numeric domain_id, required string username ) {
var body = {
'username': username
};
return apiCall( 'POST', "/whitelabel/domains/#domain_id#/subuser", {}, body );
}
/**
* IP Addresses
* https://sendgrid.api-docs.io/v3.0/ip-addresses
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-addresses/ips-add
* @hint Add IPs to your account.
* @count is the number of IPs to add to the account.
* @subusers can be an array of usernames to be assigned a send IP.
* @warmpup indicates whether or not to warmup the IPs being added.
*/
public struct function addIPs( required numeric count, array subusers = [], boolean warmpup = false ) {
var body = {
'count': count,
'warmpup': warmpup
};
if( arraylen( subusers ) ){
body[ 'subusers' ] = subusers;
}
return apiCall( 'POST', "/ips", {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-addresses/ips-remaining
* @hint Gets amount of IP Addresses that can still be created during a given period and the price of those IPs.
*/
public struct function getIPsRemaining( ) {
return apiCall( 'GET', "/ips/remaining");
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-addresses/retrieve-all-ip-addresses
* @hint Retrieve all IP addresses
* @ip is an IP address to get (Optional)
* @subuser is a subuser you are requesting for (Optional)
* @exclude_whitelabels provides the ability to exclude reverse DNS records (whitelabels)
* @sort_by_direction is the direction to sort the results (desc, asc)
*/
public struct function listAllIPs( string ip = '', string subuser = '', boolean exclude_whitelabels = false, string sort_by_direction = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
if ( len(ip) ) params[ 'ip' ] = ip;
if ( len(subuser) ) params[ 'subuser' ] = subuser;
params[ 'exclude_whitelabels' ] = exclude_whitelabels;
if ( len(sort_by_direction) ) params[ 'sort_by_direction' ] = sort_by_direction;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/ips", params );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-addresses/retrieve-all-assigned-ips
* @hint Retrieve all assigned IPs (Throws internal error even on sendgrids sample)
*/
public struct function getIPsAssigned( ) {
return apiCall( 'GET', "/ips/assigned");
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-addresses/retrieve-all-ip-pools-an-ip-address-belongs-to
* @hint Retrieve all IP pools an IP address belongs to
*/
public struct function getIPPools( required string ip = '' ) {
return apiCall( 'GET', "/ips/#ip#" );
}
/**
* IP Pools
* https://sendgrid.api-docs.io/v3.0/ip-pools
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/create-an-ip-pool
* @hint Create an IP pool. Note that before you can create an IP Pool, you need to activate the IP in your SendGrid account.
*/
public struct function createIPPool( required string name ) {
var body = {
'name': name
};
return apiCall( 'POST', "/ips/pools", {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/retrieve-all-ip-pools
* @hint Retrieve all IP pools.
*/
public struct function listAllIPPools( ) {
return apiCall( 'GET', "/ips/pools");
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/retrieve-all-ips-in-a-specified-pool
* @hint Retrieve all IPs in a specified pool.
* @ippool is the name of the IP pool you are retrieving IPs for.
*/
public struct function getPoolIPs( required string ippool = '' ) {
return apiCall( 'GET', "/ips/pools/#ippool#");
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/update-an-ip-pool-s-name
* @hint Update an IP pool’s name.
* @name is the name of the IP pool that you want to rename.
* @new_pool_name is the new name for your IP pool.
*/
public struct function updatePoolName( required string name, required string new_pool_name ) {
var body = {
'name': new_pool_name
};
return apiCall( 'PUT', "/ips/pools/#name#", {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/delete-an-ip-pool
* @hint Delete an IP pool.
* @name is the name of the IP pool that you want to delete.
*/
public struct function deleteIPPool( required string name ) {
return apiCall( 'DELETE', "/ips/pools/#name#" );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/add-an-ip-address-to-a-pool
* @hint Add an IP address to a pool
* @name is the name of the IP pool that you want to add the IP to.
* @ip is the IP address that you want to add to an IP pool.
*/
public struct function addIPToPool( required string name, required string ip ) {
var body = {
'ip': ip
};
return apiCall( 'POST', "/ips/pools/#name#/ips", {}, body );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/ip-pools/remove-an-ip-address-from-a-pool
* @hint Remove an IP address from a pool.
* @name is the name of the IP pool that you want to delete an IP from.
* @ip is the IP address that you are removing.
*/
public struct function deleteIPFromPool( required string name, required string ip ) {
return apiCall( 'DELETE', "/ips/pools/#name#/ips/#ip#" );
}
/**
* Users API
* https://sendgrid.api-docs.io/v3.0/users-api
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/get-a-user-s-profile
* @hint Get a user's profile
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getUserProfile( string on_behalf_of = '' ) {
return apiCall( 'GET', "/user/profile", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/update-a-user-s-profile
* @hint Update a user's profile
* @firstName is the first name of the user.
* @lastName is the last name of the user.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateUserProfile( string firstName = '', string lastName = '', string on_behalf_of = '' ) {
var body = {};
if( len( firstName ) ){
body[ 'first_name' ] = firstName;
}
if( len( lastName ) ){
body[ 'last_name' ] = lastName;
}
return apiCall( 'PATCH', "/user/profile", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/get-a-user-s-account-information
* @hint Get a user's account information.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getUserAccount( string on_behalf_of = '' ) {
return apiCall( 'GET', "/user/account", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/retrieve-your-account-email-address
* @hint Retrieve your account email address
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getUserEmail( string on_behalf_of = '' ) {
return apiCall( 'GET', "/user/email", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/update-your-account-email-address
* @hint Update your account email address
* @email is the new email address that you would like to use for your account.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateUserEmail( required string email, string on_behalf_of = '' ) {
var body = {
'email': email
};
return apiCall( 'PUT', "/user/email", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/retrieve-your-username
* @hint Retrieve your username
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getUserUsername( string on_behalf_of = '' ) {
return apiCall( 'GET', "/user/username", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/update-your-username
* @hint Update your username
* @username is the new username you would like to use for your account.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateUserUsername( required string username, string on_behalf_of = '' ) {
var body = {
'username': username
};
return apiCall( 'PUT', "/user/username", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/update-your-password
* @hint Update your password
* @oldpassword is the old password for your account.
* @newpassword is the new password you would like to use for your account.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateUserPassword( required string oldpassword, required string newpassword, string on_behalf_of = '' ) {
var body = {
'new_password': newpassword,
'old_password': oldpassword
};
return apiCall( 'PUT', "/user/password", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/users-api/retrieve-your-credit-balance
* @hint Retrieve your credit balance
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getUserCreditBalance( string on_behalf_of = '' ) {
return apiCall( 'GET', "/user/credits", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* Webhooks API
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Webhooks/event.html
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/retrieve-event-webhook-settings
* @hint Retrieve Event Webhook settings
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getEventWebhookSettings( string on_behalf_of = '') {
return apiCall( 'GET', "/user/webhooks/event/settings", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/update-event-notification-settings
* @hint Update a webhook's event notification settings
* @webhook should be an instance of the `helpers.webhook` component. However, if you want to create and pass in the struct or json yourself, you can.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function updateEventWebhookSettings( required any webhook, string on_behalf_of = '' ) {
var body = {};
if ( isValid( 'component', webhook ) ){
body = webhook.build();
} else {
body = webhook;
}
return apiCall( 'PATCH', "/user/webhooks/event/settings", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/test-event-notification-settings
* @hint Test your event webhook by sending a fake event notification post to the provided URL.
* @webhook should be an instance of the `helpers.webhook` component. However, if you want to create and pass in the struct or json yourself, you can.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function testEventWebhook( required any webhook, string on_behalf_of = '' ) {
var body = {};
if ( isValid( 'component', webhook ) ){
body = webhook.buildTest();
} else {
body = webhook;
}
return apiCall( 'POST', "/user/webhooks/event/test", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/retrieve-signed-webhook-public-key
* @hint Retrieve your signed webhook's public key.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getEventWebhookSignedPublicKey( string on_behalf_of = '') {
return apiCall( 'GET', "/user/webhooks/event/settings/signed", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/enable-disable-signed
* @hint Enable or disable signing of the Event Webhook.
* @enabled is boolean value that either enables or disables signing of the Event Webhook using this endpoint.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function enableEventSignedWebhook( required boolean enabled, string on_behalf_of = '' ) {
var body = {
'enabled': enabled
};
return apiCall( 'PATCH', "/user/webhooks/event/settings/signed", {}, body, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/retrieve-parse-webhook-settings
* @hint Retrieve your current inbound parse webhook settings.
* @on_behalf_of generates the API call as if the subuser account was making the request
*/
public struct function getEventWebhookParseSettings( string on_behalf_of = '') {
return apiCall( 'GET', "/user/webhooks/parse/settings", {}, {}, parseSubUser( on_behalf_of ) );
}
/**
* @docs https://sendgrid.api-docs.io/v3.0/webhooks/retrieves-inbound-parse-webhook-statistics
* @hint Retrieve the statistics for your Parse Webhook usage.
* @start_date is the starting date of the statistics to retrieve. Must follow format YYYY-MM-DD.
* @end_date is the end date of the statistics to retrieve. Defaults to today. Must follow format YYYY-MM-DD.
* @aggregated_by indicates how you would like the statistics to by grouped. Allowed Values: `day`, `week`, `month` (Optional)
*/
public struct function getEventWebhookParseStats( required string start_date, string end_date = '', string aggregated_by = '', numeric limit = 0, numeric offset = 0 ) {
var params = {};
params[ 'start_date' ] = start_date;
if (len(end_date)) params[ 'end_date' ] = end_date;
if (len(aggregated_by)) params[ 'aggregated_by' ] = aggregated_by;
if ( limit ) params[ 'limit' ] = limit;
if ( offset ) params[ 'offset' ] = offset;
return apiCall( 'GET', "/user/webhooks/parse/stats", params );
}
/**
* Blocks API
* https://sendgrid.com/docs/API_Reference/Web_API_v3/blocks.html
*/
/**
* @docs https://sendgrid.api-docs.io/v3.0/blocks-api/retrieve-all-blocks
* @hint Retrieve a list of all email addresses that are currently on your blocks list.
* @start_time is the start of the time range when the blocked email was created. If numeric, it's assumed to be a unix timestamp. Otherwise, it's presumed to be a valid date that will be converted to a unix timestamp automatically
* @end_time is the end of the time range when the blocked email was created. If numeric, it's assumed to be a unix timestamp. Otherwise, it's presumed to be a valid date that will be converted to a unix timestamp automatically
*/
public struct function listBlocks( any start_time = 0, any end_time = 0, numeric limit = 0, numeric offset = 0 ) {
var params = {};