This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-campaignmonitor-api.php
2428 lines (2298 loc) · 89.8 KB
/
wp-campaignmonitor-api.php
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
<?php
/**
* WP Campaign Monitor API
*
* @link https://www.campaignmonitor.com/api/ API Docs
* @package WP-API-Libraries\WP-CampaignMonitor-API
*/
/*
* Plugin Name: WP Campaign Monitor API
* Plugin URI: https://github.com/wp-api-libraries/wp-campaignmonitor-api
* Description: Perform API requests to Campaign Monitor in WordPress.
* Author: WP API Libraries
* Version: 1.0.0
* Author URI: https://wp-api-libraries.com
* GitHub Plugin URI:https://github.com/wp-api-libraries/wp-campaignmonitor-api
* GitHub Branch: master
*/
/* Exit if accessed directly. */
if ( ! defined( 'ABSPATH' ) ) { exit; }
// Include base api class.
include_once( 'wp-api-libraries-base.php' );
/* Check if class exists. */
if ( ! class_exists( 'CampaignMonitorAPI' ) ) {
/**
* CampaignMonitorAPI class.
*
* @link https://www.campaignmonitor.com/api/ API Docs
*/
class CampaignMonitorAPI extends WpCMLibrariesBase {
/**
* The API key with which all calls are made. Can be either an account API
* token or a client API token.
*
* @var string
* @access private
*/
private $api_key;
/**
* BaseAPI Endpoint, at which all calls are made.
*
* @var string
* @access protected
*/
protected $base_uri = 'https://api.createsend.com/api/v3.1';
/**
* Return format. XML or JSON.
*
* @var string
* @access private
*/
private $format;
/**
* Whether to return responses pretty printed or not.
*
* @var bool
* @access private
*/
private $pretty_print;
/**
* Construction function.
*
* Assigns API Key, format, and whether to pretty print or not outputs.
*
* @access public
* @param string $api_key The API key with which to make requests (either
* an account API key or a client API key).
* @param string $format (Default: 'json') The format that most (not all)
* responses should be formatted to. Acceptable
* values are 'json' and 'xml'.
* @param bool $pretty_print (Default: false) Whether to pretty print or not
* outputs.
* @return void
*/
public function __construct( $api_key, $format = 'json', $pretty_print = false ) {
$this->api_key = $api_key;
$this->format = $format;
$this->pretty_print = $pretty_print;
}
/**
* Change API key (usually for bouncing between client and account status).
*
* @access public
* @param string $api_key The API key.
*/
public function set_api_key( $api_key ){
$this->api_key = $api_key;
}
/**
* Set headers (internal call).
*
* @access protected
*/
protected function set_headers(){
$this->args['headers'] = array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode( $this->api_key . ':nopass'),
);
}
/**
* Clear headers (internal call).
*
* @access protected
* @return void
*/
protected function clear(){
$this->args = array();
}
/**
* Run a build_request( args )->fetch() call.
*
* @access protected
* @param string $request The route to make the call to.
* @param array $args (Default: array()) An array/object of arguments. If
* the call is a GET request, then the arguments well
* be formatted as an <code>http_query_string</code>.
* Otherwise, it will json_encoded and saved into the
* body of the request.
* @param string $method (Default: 'GET') The type of request to be made
* (ie: 'GET', 'POST', 'DELETE', etc).
* @return object The request.
*/
protected function run( $request, $args = array(), $method = 'GET', $use_other = false ){
return $this->build_request( '/' . $request, $args, $method, $use_other )->fetch();
}
/**
* Prepare a request.
*
* @access protected
* @param string $request The route to make the call to.
* @param array $args (Default: array()) An array/object of arguments. If
* the call is a GET request, then the arguments well
* be formatted as an <code>http_query_string</code>.
* Otherwise, it will json_encoded and saved into the
* body of the request.
* @param string $method (Default: 'GET') The type of request to be made
* (ie: 'GET', 'POST', 'DELETE', etc).
* @return object The request.
*/
protected function build_request( $request, $args = array(), $method = 'GET', $use_other = false ){
if( $this->pretty_print && $method === 'GET' ) {
$args += array('pretty' => true );
}
if( $use_other === true ){
return parent::build_request( $request, $args, $method );
}
$request .= '.' . $this->format;
return parent::build_request( $request, $args, $method );
}
/** OAUTH. */
/** ACCOUNT. */
/**
* Getting your clients
*
* Contains a list of all the clients in your account, including their name
* and ID.
*
* @access public
* @return object List of all the clients in your account.
*/
public function get_clients() {
return $this->run( 'clients' );
}
/**
* Getting your billing details.
*
* Returns billing details for your account, including the number of credits
* in your account.
*
* @access public
* @return object Returns billing details for your account, including the
* number of credits in your account.
*/
public function get_billing_details() {
return $this->run( 'billingdetails' );
}
/**
* Get valid countries
*
* Contains a list of all the valid countries accepted as input when a country
* is required, typically when creating a client.
*
* @access public
* @return object List of all valid countries.
*/
public function get_valid_countries() {
return $this->run( 'countries' );
}
/**
* Getting valid timezones
*
* Contains a list of all the valid timezones accepted as input when a timezone
* is required, typically when creating a client.
*
* @access public
* @return object List of all valid timezones accepted as input.
*/
public function get_valid_timezones() {
return $this->run( 'timezones' );
}
/**
* Getting current date
*
* Contains the current date and time in your account’s timezone. This is useful
* when, for example, you are syncing your Campaign Monitor lists with an external
* list, allowing you to accurately determine the time on our server when you
* carry out the synchronization.
*
* @access public
* @return object Current date.
*/
public function get_systemdate() {
return $this->run( 'systemdate' );
}
/**
* Adding an administrator
*
* Adds a new administrator to the account. An invitation will be sent to the
* new administrator via email.
*
* @access public
* @param string $email Email to perform the action on.
* @param string $name Name to assign to this item.
* @return object Confirmation code and email of user added.
*/
public function add_administrator( $email, $name ) {
$args = array(
'EmailAddress' => $email,
'Name' => $name,
);
return $this->run( 'admins', $args, 'POST' );
}
/**
* Updating an administrator
*
* Updates the email address and/or name of an administrator.
*
* Note: the email value in the query string is the old email address. Use the
* EmailAddress property in the request body to change the email address.
*
* @access public
* @param string $email Email to perform the action on.
* @param string $new_email Email you would like to change the admin to.
* (Does not have to be different).
* @param string $new_name Name you would like to change the admin to. (Does
* not have to be different).
* @return object Confirmation code and email of user modified.
*/
public function update_administrator( $email, $new_email, $new_name ) {
$request = 'admins.' . $this->format . '?email=' . $email;
$args = array(
'EmailAddress' => $email,
'Name' => $name,
);
return $this->run( $request, $args, 'PUT', true );
}
/**
* Getting administrators
*
* Contains a list of all (active or invited) administrators associated with
* a particular account.
*
* @access public
* @return object List of all administrators.
*/
public function get_administrators() {
return $this->run( 'admins' );
}
/**
* Administrator details
*
* Returns the details of a single administrator associated with an account.
*
* @access public
* @param string $email Email to get details about.
* @return object Details for an admin.
*/
public function get_admin_details( $email ) {
$args = array(
'email' => $email,
);
return $this->run( 'admins', $args );
}
/**
* Deleting an administrator
*
* Changes the status of an active administrator to a deleted administrator.
* They will no longer be able to log into this account
*
* @access public
* @param string $email Email to perform the action on.
* @return object Confirmation code.
*/
public function delete_admin( $email ) {
$request = 'admins' . $this->format . '?email=' . $email;
return $this->run( $request, array(), 'DELETE', true );
}
/**
* Setting primary contact
*
* Sets the primary contact for the account to be the administrator with the
* specified email address.
*
* @access public
* @param string $email Email to perform the action on.
* @return object Confirmation code
*/
public function set_primary_account( $email ) {
$request = 'primarycontact' . $this->format . '?email=' . $email;
return $this->run( $request, array(), 'PUT', true );
}
/**
* Getting primary contact
*
* Returns the email address of the administrator who is selected as the primary
* contact for this account.
*
* @access public
* @return object Primary account email.
*/
public function get_primary_account() {
return $this->run( 'primarycontact' );
}
/**
* Single sign on
*
* Initiates a new login session for the member with the specified email address.
*
* Before you can use this method you’ll have to get in touch with CampaignMonitor
* to obtain an IntegratorID. Once you’ve registered you can create login sessions
* for account members, optionally directing them to a specific page. This method
* will return a single use url which will create the login session. This is
* usually used as the source of an iframe for embedding Campaign Monitor within
* your own application.
*
* Some UI elements can be hidden from the member via the Chrome parameter.
* Valid options for this parameter are all, tabs or none.
*
* @access public
* @param string $email Email to perform the action on.
* @param string $url See https://www.campaignmonitor.com/api/account/#single-sign-on
* @param string $integrator_id ID of integrator.
* @param string $client_id Client to perform action on.
* @param string $chrome (Default: 'None') ome UI elements can be hidden
* from the member via the Chrome parameter.
* Valid options for this parameter are all, tabs
* or none.
* @return object Confirmation code and session URL.
*/
public function single_sign_on( $email, $url, $integrator_id, $client_id, $chrome = 'None') {
$args = array(
'Email' => $email,
'Chrome' => $chrome,
'Url' => $url,
'IntegratorID' => $integrator_id,
'ClientID' => $client_id,
);
return $this->run( 'externalsession', $args, 'PUT' );
}
/** CAMPAIGNS. */
/**
* Creating a draft campaign
*
* Creates (but does not send) a draft campaign ready to be tested as a preview
* or sent. Set the basic campaign information (name, subject, from name and
* from email), the URL of the HTML content plus the lists and/or segments you’d
* like it to be eventually sent to. We’ll automatically move all CSS inline
* for the HTML component.
*
* Note that you may optionally specify a TextUrl field in your input if you
* want to specify text content for the campaign. If you don’t specify TextUrl
* or if TextUrl is left empty, the text content for the campaign will be
* automatically generated from the HTML content.
*
* @access public
* @param string $client_id Client to perform action on.
* @param string $name Name to assign to this item.
* @param string $subject Subject of the email
* @param string $from_name Name of sender
* @param string $from_email Email of sender
* @param string $html_url URL of the html from which to pull
* @param array $list_ids List of IDs of lists to add emails to
* @param array $segment_ids List of IDs of segments to add to
* @param string $reply_to (Default '') Optionally different ReplyTo email
* @param string $text_url (Default '') Optional url of which to draw text
* of the email. If not provided, will be generated
* from the HTML.
* @return object ID of campaign created.
*/
public function add_draft_campaign( $client_id, $name, $subject, $from_name, $from_email, $html_url, $list_ids, $segment_ids, $reply_to = '', $text_url = '' ) {
$args = array(
'Name' => $name,
'Subject' => $subject,
'FromName' => $from_name,
'FromEmail' => $from_email,
'HtmlUrl' => $html_url,
'ListIDs' => $list_ids,
'SegmentIDs' => $segment_ids,
);
if( $reply_to !== '' ){
$args['ReplyTo'] = $reply_to;
}
if( $text_url !== '' ){
$args['TextUrl'] = $text_url;
}
return $this->run( 'campaigns/' . $client_d, $args, 'POST' );
}
/**
* Creating a campaign from a template
*
* Creates (but does not send) a draft campaign based on a template ready to
* be tested as a preview or sent. Set the basic campaign information (name,
* subject, from name and from email), the template ID, the template content,
* plus the lists and/or segments you’d like it to be eventually sent to. You
* can find the template ID you want to use by getting a client’s templates.
*
* Note: Creating a campaign from a Canvas template is currently not supported.
*
* See the link below for what the format of the $campaign object should look
* like.
*
* https://www.campaignmonitor.com/api/campaigns/#creating-campaign-template
*
* @access public
* @param string $client_id Client to perform action on.
* @param object $campaign A campaign object. See link above.
* @return object ID of campaign created.
*/
public function add_campaign_from_template( $client_id, $campaign ) {
return $this->run( "campaigns/$client_id/fromtemplate", $campaign, 'POST' );
}
/**
* Sending a draft campaign
*
* Schedules an existing draft campaign for sending either immediately or a
* custom date and time in the future. For campaigns with more than 5 recipients,
* you must have sufficient email credits, a saved credit card or an active
* monthly billed account.
*
* Free sending limitation: When sending campaigns to 5 or less recipients
* (which are free of charge), you can send to a maximum of 50 unique email
* addresses per day.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param string $confirmation_email An email address to send the confirmation
* to that the campaign has been sent.
* @param string $send_date Date of which the campaign should be
* scheduled to be sent.
* @return object Confirmation code.
*/
public function send_draft_campaign( $campaign_id, $confirmation_email, $send_date ) {
$args = array(
'ConfirmationEmail' => $confirmation_email,
'SendDate' => $send_date,
);
return $this->run( "campaigns/$campaign_id/send", $args, 'POST' );
}
/**
* Sending a campaign preview
*
* Send a preview of any draft campaign to a number of email addresses you
* specify. You can also set how we should treat any personalization tags in
* your draft campaign.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param array $preview_recipients A list of emails to send previews to.
* @param string $personalize Whether to personalize it or not. Acceptable
* values are 'Fallback', 'Random', or a valid
* email address.
* @return object Confirmation code.
*/
public function send_campaign_preview( $campaign_id, $preview_recipients, $personalize ) {
$args = array(
'PreviewRecipients' => $preview_recipients,
'Personalize' => $personalize,
);
return $this->run( "campaigns/$campaign_id/sendpreview", $args, 'POST' );
}
/**
* Campaign Summary
*
* Provides a basic summary of the results for any sent campaign such as the
* number of recipients, opens, clicks, unsubscribes, etc to date. Also includes
* the web version URL, and the public Worldview URL for the campaign.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @return object Campaign summary.
*/
public function get_campaign_summary( $campaign_id ) {
return $this->run( "campaigns/$campaign_id/summary" );
}
/**
* Campaign email client usage
*
* Lists the email clients subscribers used to open the campaign. Each entry
* includes the email client name, the email client version, the percentage of
* subscribers who used it, and the actual number of subscribers who used it
* to open the campaign.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @return object The email clients used to open the campaign + some.
*/
public function get_list_campaign_client_emails( $campaign_id ) {
return $this->run( "campaigns/$campaign_id/emailclientusage" );
}
/**
* Campaign lists and segments
*
* Returns the lists and segments any campaign was sent to.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @return object Lists and segments any campaign was sent to.
*/
public function get_lists_and_segments_campaign( $campaign_id ) {
return $this->run( "campaigns/$campaign_id/listsandsegments" );
}
/**
* Campaign recipients
*
* Retrieves a paged result representing all the subscribers that a given campaign
* was sent to. This includes their email address and the ID of the list they
* are a member of. You have complete control over how results should be returned
* including page size, sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_recipients( $campaign_id, $page_number = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'page' => $page_number,
'pagesize' => $paze_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/recipients", $args );
}
/**
* Campaign bounces
*
* Retrieves a paged result representing all the subscribers who bounced for
* a given campaign, and the type of bounce (Hard = Hard Bounce, Soft = Soft
* Bounce). You have complete control over how results should be returned
* including page size, sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_bounces( $campaign_id, $date = '', $page = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'date' => $date,
'page' => $page,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/bounces", $args );
}
/**
* Campaign opens
*
* Retrieves a paged result representing all subscribers who opened a given
* campaign, including the date/time and IP address from which they opened the
* campaign. When possible, the latitude, longitude, city, region, country code,
* and country name as geocoded from the IP address, are also returned. You have
* complete control over how results should be returned including page size,
* sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_opens( $campaign_id, $date = '', $page_number = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'date' => $date,
'page' => $page_number,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/opens", $args );
}
/**
* Campaign clicks
*
* Retrieves a paged result representing all subscribers who clicked a link
* in a given campaign, including the date/time and IP address from which they
* clicked the link. When possible, the latitude, longitude, city, region, country
* code, and country name as geocoded from the IP address, are also returned. You
* have complete control over how results should be returned including page size,
* sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_clicks( $campaign_id, $date = '', $page_number = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'date' => $date,
'page' => $page_number,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/clicks", $args );
}
/**
* Campaign unsubscribes
*
* Retrieves a paged result representing all subscribers who unsubscribed from
* the email for a given campaign, including the date/time and IP address they
* unsubscribed from. You have complete control over how results should be returned
* including page size, sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_unsubscribes( $campaign_id, $date = '', $page_number = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'date' => $date,
'page' => $page_number,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/unsubscribes", $args );
}
/**
* Campaign spam complaints
*
* Retrieves a paged result representing all subscribers who marked the given
* campaign as spam, including the subscriber’s list ID and the date/time they
* marked the campaign as spam. You have complete control over how results should
* be returned including page size, sort order and sort direction.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object The results of your search.
*/
public function get_campaign_spam_complaints( $campaign_id, $date = '', $page_number = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'date' => $date,
'page' => $page_number,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "campaigns/$campaign_id/spam", $args );
}
/**
* Deleting a campaign
*
* Deletes a campaign from your account. For draft and scheduled campaigns (prior
* to the time of scheduling), this will prevent the campaign from sending.
* If the campaign is already sent or in the process of sending, it will remove
* the campaign from the account.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @return object Confirmation code.
*/
public function delete_campaign( $campaign_id ) {
return $this->run( 'campaigns/' . $campaign_id, array(), 'DELETE' );
}
/**
* Unscheduling a campaign
*
* Cancels the sending of the campaign and moves it back into the drafts. If
* the campaign is already sent or in the process of sending, this operation
* will fail.
*
* @access public
* @param string $campaign_id ID of campaign to perform the action on.
* @return object Confirmation code.
*/
public function unschedule_campaign( $campaign_id ) {
return $this->run( "campaigns/$campaign_id/unschedule", array(), 'POST' );
}
/** CLIENTS. */
/**
* Creating a client
*
* Creates a new client in your account with basic contact information and no
* access to the application. Client billing options are set once the client
* is created.
*
* @access public
* @param string $company_name Name of the company.
* @param string $country
* @param string $timezone
* @return object Confirmation and ID of client created.
*/
public function add_client( $company_name, $country = 'United States of America', $timezone = '(GMT-08:00) Pacific Time (US & Canada)') {
$args = array(
'CompanyName' => $company_name,
'Country' => $country,
'TimeZone' => $timezone,
);
return $this->run( 'clients', $args, 'POST' );
}
/**
* Getting a client's details
*
* Get the complete details for a client including their API key, access level,
* contact details and billing settings.
*
* If there is only one Person in this Client, their Email Address, Contant
* Name and Access Details are returned. If there are multiple Persons in this
* Client, or no Persons at all, these fields are omitted in the response.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object Client details.
*/
public function get_client_details( $client_id ) {
return $this->run( 'clients/' . $client_id );
}
/**
* Getting sent campaigns
*
* Returns a list of all sent campaigns for a client including from name, from
* email, reply to email, web version URL, ID, subject, name, date sent, and
* the total number of recipients.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object List of all sent campaigns for this client
*/
public function get_sent_campaign( $client_id ) {
return $this->run( "clients/$client_id/campaigns" );
}
/**
* Getting scheduled campaigns
*
* Returns all currently scheduled campaigns for a client including from name,
* from email, reply to email, preview URL, ID, subject, name, date created,
* date scheduled, and the scheduled timezone.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object A list of all currently scheduled campaigns
*/
public function get_schedule_campaign( $client_id ) {
return $this->run( "clients/$client_id/scheduled" );
}
/**
* Getting draft campaigns
*
* Returns a list of all draft campaigns belonging to that client including from
* name, from email, reply to email, preview URL, ID, subject, name, and the
* date the draft was created.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object A list of all draft campaigns related to this client.
*/
public function get_draft_campaign( $client_id ) {
return $this->run( "clients/$client_id/drafts" );
}
/**
* Getting subscriber lists
*
* Returns all the subscriber lists that belong to that client, including the
* list name and ID.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object A list of subscribers lists. Heh.
*/
public function get_subscriber_lists( $client_id ) {
return $this->run( "clients/$client_id/lists" );
}
/**
* Getting lists for an email address
*
* Returns all the subscriber lists across the client, to which an email address
* is subscribed.
*
* For each list to which the email address is subscribed, you will receive the
* list ID, list name, the state of the subscriber on the list, and the date the
* subscriber was added to the list (in the client’s timezone).
*
* @access public
* @param string $client_id Client to perform action on.
* @param string $email Email to perform the action on.
* @return object Get a list of sub lists for client, where an email
* is present.
*/
public function get_lists_email_address( $client_id, $email ) {
return $this->run( "clients/$client_id/listsforemail", array('email' => $email ) );
}
/**
* Getting segments
*
* Contains a list of all list segments belonging to a particular client.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object A list of all list segments for this client.
*/
public function get_segments( $client_id ) {
return $this->run( "clients/$client_id/segments" );
}
/**
* Getting suppression list
*
* Contains a paged result representing the client’s suppression list.
*
* @access public
* @param string $client_id Client to perform action on.
* @param int $page_number (Default: 1) Pagination, which page to
* start on.
* @param int $page_size (Default: 1000) Pagination, how many results
* to display per page.
* @param string $order_field (Default: 'email') The field which should
* be used to order the results. Acceptable
* values are 'list', 'email', and 'date'.
* @param string $order_direction (Defaul: 'asc') Whether to display results
* in an ascending ('asc') or descending ('desc')
* order.
* @return object Paginated result of the client's suppression.
*/
public function get_suppression_list( $client_id, $page = 1, $page_size = 1000, $order_field = 'email', $order_direction = 'asc' ) {
$args = array(
'page' => $page,
'pagesize' => $page_size,
'orderfield' => $order_field,
'orderdirection' => $order_direction,
);
return $this->run( "clients/$client_id/suppressionlist", $args );
}
/**
* Suppress email addresses
*
* Adds the email addresses provided to the client’s suppression list.
*
* @access public
* @param string $client_id Client to perform action on.
* @param array $email_address An array of emails to add.
* @return object Confirmation code.
*/
public function suppress_email_address( $client_id, $email_addresses ) {
return $this->run( "clients/$client_id/suppress", array( 'EmailAddresses' => $email_addresses) );
}
/**
* Unsuppress an email address
*
* Unsuppresses an email address by removing the email address from a client’s
* suppression list.
*
* @access public
* @param string $client_id Client to perform action on.
* @param string $email Email to perform the action on.
* @return object Confirmation code
*/
public function unsuppress_email_address( $client_id, $email ) {
$request = "clients/$client_id/unsuppress.$this->format?email=$email";
return $this->run( $request, array(), 'PUT', true );
}
/**
* Getting templates
*
* Contains a list of the templates belonging to the client including the ID,
* name and a URL for a screenshot and HTML preview of the template.
*
* @access public
* @param string $client_id Client to perform action on.
* @return object A list of the templates belonging to the client.
*/
public function get_templates( $client_id ) {
return $this->run( "clients/$client_id/templates/" );
}