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 142
/
sample-list.subscriber.php
executable file
·107 lines (93 loc) · 4.01 KB
/
sample-list.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
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_Subscriber;
use FuelSdk\ET_List_Subscriber;
use FuelSdk\ET_List;
try {
// 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
$NewListName = "PHPSDKListSubscriber";
$SubscriberTestEmail = "[email protected]";
$myclient = new ET_Client();
// Create List
print "Create List \n";
$postContent = new ET_List();
$postContent->authStub = $myclient;
$postContent->props = array("ListName" => $NewListName, "Description" => "This list was created with the RubySDK", "Type" => "Private");
$postResponse = $postContent->post();
print_r('Post Status: '.($postResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$postResponse->code."\n";
print 'Message: '.$postResponse->message."\n";
print 'Results Length: '. count($postResponse->results)."\n";
print 'Results: '."\n";
print_r($postResponse->results);
print "\n---------------\n";
if ($postResponse->status){
$newListID = $postResponse->results[0]->NewID;
// Create Subscriber on List
print "Create Subscriber on List \n";
$subCreate = new ET_Subscriber();
$subCreate->authStub = $myclient;
$subCreate->props = array("EmailAddress" => $SubscriberTestEmail, "Lists" => array("ID" => $newListID));
$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";
if (!$postResult->status) {
// If the subscriber already exists in the account then we need to do an update.
// Update Subscriber On List
if ($postResult->results[0]->ErrorCode == "12014"){
// Update Subscriber to add to List
print "Update Subscriber to add to List \n";
$subPatch = new ET_Subscriber();
$subPatch->authStub = $myclient;
$subPatch->props = array("EmailAddress" => $SubscriberTestEmail, "Lists" => array("ID" => $newListID));
$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 all Subscribers on the List
print "Retrieve all Subscribers on the List \n";
$getList = new ET_List_Subscriber();
$getList->authStub = $myclient;
$getList->filter = array('Property' => 'ListID','SimpleOperator' => 'equals','Value' => $newListID);
$getList->props = array("ObjectID","SubscriberKey","CreatedDate","Client.ID","Client.PartnerClientKey","ListID","Status");
$getResponse = $getList->get();
print_r('Get Status: '.($getResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$getResponse->code."\n";
print 'Message: '.$getResponse->message."\n";
print_r('More Results: '.($getResponse->moreResults ? 'true' : 'false')."\n");
print 'Results Length: '. count($getResponse->results)."\n";
print 'Results: '."\n";
print_r($getResponse->results);
print "\n---------------\n";
// Delete List
print "Delete List \n";
$deleteList = new ET_List();
$deleteList->authStub = $myclient;
$deleteList->props = array("ID" => $newListID);
$deleteResponse = $deleteList->delete();
print_r('Delete Status: '.($deleteResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$deleteResponse->code."\n";
print 'Message: '.$deleteResponse->message."\n";
print 'Results Length: '. count($deleteResponse->results)."\n";
print 'Results: '."\n";
print_r($deleteResponse->results);
print "\n---------------\n";
}
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>