This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
/
sample-subscriber.php
executable file
·141 lines (126 loc) · 5.72 KB
/
sample-subscriber.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
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_Subscriber;
try {
$myclient = new ET_Client();
// NOTE: These examples only work in accounts where the SubscriberKey functionality is not enabled
// SubscriberKey will need to be included in the props if that feature is enabled
$SubscriberTestEmail = "[email protected]";
// Create Subscriber
print "Create Subscriber \n";
$subCreate = new ET_Subscriber();
$subCreate->authStub = $myclient;
$subCreate->props = array("SubscriberKey" => "PHPSDKSubscriber".uniqid(),
"EmailAddress" => $SubscriberTestEmail,
"Attributes" => array("Name" => "First Name", "Value" => "FirstName".uniqid())
);
$postResult = $subCreate->post();
print_r('Post Status: '.($postResult->status ? 'true' : 'false')."\n");
print 'Code: '.$postResult->code."\n";
print 'Message: '.$postResult->message."\n";
print 'Results Length: '. count($postResult->results)."\n";
print 'Results: '."\n";
print_r($postResult->results);
print "\n---------------\n";
// Retrieve newly created Subscriber
print "Retrieve newly created Subscriber \n";
$retSub = new ET_Subscriber();
$retSub->authStub = $myclient;
$retSub->filter = array('Property' => 'SubscriberKey','SimpleOperator' => 'equals','Value' => $SubscriberTestEmail);
$retSub->props = array("SubscriberKey", "EmailAddress", "Status");
$getResult = $retSub->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Update Subscriber to unsubscribed
print "Updates Subscriber to unsubscribed\n";
$subPatch = new ET_Subscriber();
$subPatch->authStub = $myclient;
$subPatch->props = array("EmailAddress" => $SubscriberTestEmail, "Status" => "Unsubscribed");
$patchResult = $subPatch->patch();
print_r('Patch Status: '.($patchResult->status ? 'true' : 'false')."\n");
print 'Code: '.$patchResult->code."\n";
print 'Message: '.$patchResult->message."\n";
print 'Results Length: '. count($patchResult->results)."\n";
print 'Results: '."\n";
print_r($patchResult->results);
print "\n---------------\n";
// Retrieve Subscriber that should have status unsubscribed now
print "Retrieve Subscriber that should have status unsubscribed now \n";
$retSub = new ET_Subscriber();
$retSub->authStub = $myclient;
$retSub->filter = array('Property' => 'SubscriberKey','SimpleOperator' => 'equals','Value' => $SubscriberTestEmail);
$retSub->props = array("SubscriberKey", "EmailAddress", "Status");
$getResult = $retSub->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Delete Subscriber
print "Delete Subscriber \n";
$subDelete = new ET_Subscriber();
$subDelete->authStub = $myclient;
$subDelete->props = array("EmailAddress" => $SubscriberTestEmail);
$deleteResult = $subDelete->delete();
print_r('Delete Status: '.($deleteResult->status ? 'true' : 'false')."\n");
print 'Code: '.$deleteResult->code."\n";
print 'Message: '.$deleteResult->message."\n";
print 'Results Length: '. count($deleteResult->results)."\n";
print 'Results: '."\n";
print_r($deleteResult->results);
print "\n---------------\n";
// Retrieve Subscriber to confirm deletion
print "Retrieve Subscriber to confirm deletion \n";
$retSub = new ET_Subscriber();
$retSub->authStub = $myclient;
$retSub->filter = array('Property' => 'SubscriberKey','SimpleOperator' => 'equals','Value' => $SubscriberTestEmail);
$retSub->props = array("SubscriberKey", "EmailAddress", "Status");
$getResult = $retSub->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Do not run the "Retrieve All Subscribers" request for testing if you have more than 100,000 records in your account as it will take a long time to complete.
/*
// Retrieve All Subcribers with GetMoreResults
print "Retrieve All Subcribers with GetMoreResults \n";
$getSub = new ET_Subscriber();
$getSub->authStub = $myclient;
$getSub->props = array("SubscriberKey", "EmailAddress", "Status");
$getResult = $getSub->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResult->results)."\n";
print "\n---------------\n";
while ($getResult->moreResults) {
print "Continue Retrieve All Subcribers with GetMoreResults \n";
$getResult = $getSub->GetMoreResults();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResult->results)."\n";
print "\n---------------\n";
}
*/
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>