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-campaign.php
executable file
·184 lines (161 loc) · 6.99 KB
/
sample-campaign.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
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_Campaign;
use FuelSdk\ET_Campaign_Asset;
try {
# In order for this sample to run, it needs to have an asset that it can associate the campaign to
$ExampleAssetType = "EMAIL";
$ExampleAssetItemID = "90840";
$myclient = new ET_Client(true);
// Retrieve All Campaigns with GetMoreResults
print "Retrieve All Campaigns with GetMoreResults \n";
$getCamp = new ET_Campaign();
$getCamp->authStub = $myclient;
$getResult = $getCamp->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(Items): '. count($getResult->results->items)."\n";
//print 'Results: "\n"';
print_r($getResult->results);
print "\n---------------\n";
while ($getResult->moreResults) {
print "Continue Retrieve All Campaigns with GetMoreResults \n";
$getResult = $getCamp->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(Items): '. count($getResult->results->items)."\n";
print "\n---------------\n";
}
// Create a new Campaign
print "Create a new Campaign \n";
$postCamp = new ET_Campaign();
$postCamp->authStub = $myclient;
$postCamp->props = array("name" => "CampaignForPHPSDK", "description"=> "CampaignForPHPSDK", "color"=>"FF9933", "favorite"=>"false");
$postResponse = $postCamp->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) {
$IDOfpostCampaign = $postResponse->results->id;
// Retrieve the new Campaign
print "Retrieve the new Campaign \n";
$getCamp = new ET_Campaign();
$getCamp->authStub = $myclient;
$getCamp->props = array("id" => $IDOfpostCampaign);
$getResult = $getCamp->Get();
print_r('Retrieve Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Update a Campaign
print "Update a Campaign \n";
$patchCamp = new ET_Campaign();
$patchCamp->authStub = $myclient;
$patchCamp->props = array("id" => $IDOfpostCampaign, "name" => "CampaignForPHPSDK Updated!");
$patchResponse = $patchCamp->Patch();
print_r('Patch Status: '.($patchResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$patchResponse->code."\n";
print 'Message: '.$patchResponse->message."\n";
print 'Results Length: '. count($patchResponse->results)."\n";
print 'Results: '."\n";
print_r($patchResponse->results);
print "\n---------------\n";
// Retrieve the updated Campaign
print "Retrieve the updated Campaign \n";
$getCamp = new ET_Campaign();
$getCamp->authStub = $myclient;
$getCamp->props = array("id" => $IDOfpostCampaign);
$getResult = $getCamp->Get();
print_r('Retrieve Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Create a new Campaign Asset
print "Create a new Campaign Asset \n";
$postCampAsset = new ET_Campaign_Asset();
$postCampAsset->authStub = $myclient;
$postCampAsset->props = array("id" => $IDOfpostCampaign, "ids"=> array($ExampleAssetItemID), "type"=> $ExampleAssetType);
$postResponse = $postCampAsset->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){
$IDOfpostCampaignAsset = $postResponse->results[0]->id;
// Retrieve all Campaign Asset for a campaign
print "Retrieve all Campaign Asset for a campaign \n";
$getCampAsset = new ET_Campaign_Asset();
$getCampAsset->authStub = $myclient;
$getCampAsset->props = array("id" => $IDOfpostCampaign);
$getResult = $getCampAsset->Get();
print_r('Retrieve Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult);
print "\n---------------\n";
// Retrieve a single new Campaign Asset
print "Retrieve a single new Campaign Asset \n";
$getCampAsset = new ET_Campaign_Asset();
$getCampAsset->authStub = $myclient;
$getCampAsset->props = array("id" => $IDOfpostCampaign, "ids"=> array($ExampleAssetItemID), "type"=> $ExampleAssetType);
$getResult = $getCampAsset->Get();
print_r('Retrieve Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Results Length: '. count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
//Delete the new Campaign Asset
print "Delete the new Campaign Asset\n";
$deleteCampAsset = new ET_Campaign_Asset();
$deleteCampAsset->authStub = $myclient;
$deleteCampAsset->props = array("id" => $IDOfpostCampaign, "assetId" => $IDOfpostCampaignAsset);
$deleteResult = $deleteCampAsset->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";
}
// Delete a Campaign
print "Delete a Campaign \n";
$deleteCamp = new ET_Campaign();
$deleteCamp->authStub = $myclient;
$deleteCamp->props = array("id" => $IDOfpostCampaign);
$deleteResponse = $deleteCamp->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";
}
?>