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-dataextension.php
executable file
·232 lines (209 loc) · 9.58 KB
/
sample-dataextension.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
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_DataExtension;
use FuelSdk\ET_DataExtension_Column;
use FuelSdk\ET_DataExtension_Row;
try {
$myclient = new ET_Client();
//DataExtension Testing
//Get all Data Extensions
print_r("Get all Data Extensions \n");
$getDE = new ET_DataExtension();
$getDE->authStub = $myclient;
$getDE->props = array("CustomerKey", "Name");
$getResult = $getDE->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 'Result Count: '.count($getResult->results)."\n";
//print 'Results: '."\n";
//print_r($getResult->results);
print "\n---------------\n";
// Specify a name for the data extension that will be used for testing
// Note: Name and CustomerKey will be the same value
// WARNING: Data Extension will be deleted so don't use the name of a
// production data extension
$DataExtensionNameForTesting = "PHPSDKTestDE_".uniqid();
// Create a Data Extension
print_r("Create a Data Extension \n");
$postDE = new ET_DataExtension();
$postDE->authStub = $myclient;
$postDE->props = array("Name" => $DataExtensionNameForTesting, "CustomerKey" => $DataExtensionNameForTesting);
$postDE->columns = array();
$postDE->columns[] = array("Name" => "Key", "FieldType" => "Text", "IsPrimaryKey" => "true","MaxLength" => "100", "IsRequired" => "true");
$postDE->columns[] = array("Name" => "Value", "FieldType" => "Text");
$postResult = $postDE->post();
print_r('Post Status: '.($postResult->status ? 'true' : 'false')."\n");
print 'Code: '.$postResult->code."\n";
print 'Message: '.$postResult->message."\n";
print 'Result Count: '.count($postResult->results)."\n";
print 'Results: '."\n";
print_r($postResult->results);
print "\n---------------\n";
// Update a Data Extension (Add New Column)
print_r("Update a Data Extension (Add New Column) \n");
$patchDE = new ET_DataExtension();
$patchDE->authStub = $myclient;
$patchDE->props = array("Name" => $DataExtensionNameForTesting, "CustomerKey" => $DataExtensionNameForTesting);
$patchDE->columns = array();
$patchDE->columns[] = array("Name" => "AnExtraField", "FieldType" => "Text");
$patchResult = $patchDE->patch();
print_r('Patch Status: '.($patchResult->status ? 'true' : 'false')."\n");
print 'Code: '.$patchResult->code."\n";
print 'Message: '.$patchResult->message."\n";
print 'Result Count: '.count($patchResult->results)."\n";
print 'Results: '."\n";
print_r($patchResult->results);
print "\n---------------\n";
//Get single Data Extension
print_r("Get single Data Extension \n");
$getDE = new ET_DataExtension();
$getDE->authStub = $myclient;
$getDE->props = array("CustomerKey", "Name");
$getDE->filter = array('Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => $DataExtensionNameForTesting);
$getResult = $getDE->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 'Result Count: '.count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
//Get all Data Extensions Columns filter by specific DE
print_r("Get all Data Extensions Columns filter by specific DE \n");
$getDEColumns = new ET_DataExtension_Column();
$getDEColumns->authStub = $myclient;
$getDEColumns->props = array("CustomerKey", "Name");
$getDEColumns->filter = array('Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => $DataExtensionNameForTesting);
$getResult = $getDEColumns->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 'Result Count: '.count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Add a row to a DataExtension
print_r("Add a row to a DataExtension \n");
$postDRRow = new ET_DataExtension_Row();
$postDRRow->authStub = $myclient;
$postDRRow->props = array("Key" => "PHPSDKTEST", "Value" => "ItWorks");
$postDRRow->Name = $DataExtensionNameForTesting;
$postResult = $postDRRow->post();
print_r('Post Status: '.($postResult->status ? 'true' : 'false')."\n");
print 'Code: '.$postResult->code."\n";
print 'Message: '.$postResult->message."\n";
print 'Result Count: '.count($postResult->results)."\n";
print 'Results: '."\n";
print_r($postResult->results);
print "\n---------------\n";
// Add a row to a DataExtension (Specify CustomerKey instead of Name)
print_r("Add a row to a DataExtension (Specify CustomerKey instead of Name) \n");
$postDRRow = new ET_DataExtension_Row();
$postDRRow->authStub = $myclient;
$postDRRow->props = array("Key" => "PHPSDKTEST2", "Value" => "ItWorks");
$postDRRow->CustomerKey = $DataExtensionNameForTesting;
$postResult = $postDRRow->post();
print_r('Post Status: '.($postResult->status ? 'true' : 'false')."\n");
print 'Code: '.$postResult->code."\n";
print 'Message: '.$postResult->message."\n";
print 'Result Count: '.count($postResult->results)."\n";
print 'Results: '."\n";
print_r($postResult->results);
print "\n---------------\n";
//Get all Data Extensions Rows (By CustomerKey)
print_r("Get all Data Extensions Rows (By CustomerKey) \n");
$getDERows = new ET_DataExtension_Row();
$getDERows->authStub = $myclient;
$getDERows->props = array("Key", "Value");
$getDERows->CustomerKey = $DataExtensionNameForTesting;
$getResult = $getDERows->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 'Result Count: '.count($getResult->results)."\n";
//print 'Results: '."\n";
//print_r($getResult->results);
print "\n---------------\n";
// Update a row in a DataExtension
print_r("Update a row in a DataExtension \n");
$patchDRRow = new ET_DataExtension_Row();
$patchDRRow->authStub = $myclient;
$patchDRRow->props = array("Key" => "PHPSDKTEST2", "Value" => "ItWorksUPDATED!");
$patchDRRow->CustomerKey = $DataExtensionNameForTesting;
$patchResult = $patchDRRow->patch();
print_r('Patch Status: '.($patchResult->status ? 'true' : 'false')."\n");
print 'Code: '.$patchResult->code."\n";
print 'Message: '.$patchResult->message."\n";
print 'Result Count: '.count($patchResult->results)."\n";
print 'Results: '."\n";
print_r($patchResult->results);
print "\n---------------\n";
//Get rows from Data Extension using filter (By Name)
print_r("Get rows from Data Extension using filter (By Name) \n");
$getDERows = new ET_DataExtension_Row();
$getDERows->authStub = $myclient;
$getDERows->props = array("Key", "Value");
$getDERows->Name = $DataExtensionNameForTesting;
$getDERows->filter = array('Property' => 'Key','SimpleOperator' => 'equals','Value' => 'PHPSDKTEST2');
$getResult = $getDERows->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 'Result Count: '.count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Delete a row from a DataExtension
print_r("Delete a row from a DataExtension \n");
$deleteDRRow = new ET_DataExtension_Row();
$deleteDRRow->authStub = $myclient;
$deleteDRRow->props = array("Key" => "PHPSDKTEST2", "Value" => "ItWorksUPDATED!");
$deleteDRRow->CustomerKey = $DataExtensionNameForTesting;
$deleteResult = $deleteDRRow->delete();
print_r('Delete Status: '.($deleteResult->status ? 'true' : 'false')."\n");
print 'Code: '.$deleteResult->code."\n";
print 'Message: '.$deleteResult->message."\n";
print 'Result Count: '.count($deleteResult->results)."\n";
print 'Results: '."\n";
print_r($deleteResult->results);
print "\n---------------\n";
//Get all Data Extensions Rows (By CustomerKey) Again
print_r("Get all Data Extensions Rows (By CustomerKey) Again \n");
$getDERows = new ET_DataExtension_Row();
$getDERows->authStub = $myclient;
$getDERows->props = array("Key", "Value");
$getDERows->CustomerKey = $DataExtensionNameForTesting;
$getResult = $getDERows->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 'Result Count: '.count($getResult->results)."\n";
//print 'Results: '."\n";
//print_r($getResult->results);
print "\n---------------\n";
// Delete a Data Extension
print_r("Delete a Data Extension \n");
$deleteDE = new ET_DataExtension();
$deleteDE->authStub = $myclient;
$deleteDE->props = array("Name" => $DataExtensionNameForTesting, "CustomerKey" => $DataExtensionNameForTesting);
$deleteResult = $deleteDE->delete();
print_r('Delete Status: '.($deleteResult->status ? 'true' : 'false')."\n");
print 'Code: '.$deleteResult->code."\n";
print 'Message: '.$deleteResult->message."\n";
print 'Result Count: '.count($deleteResult->results)."\n";
print 'Results: '."\n";
print_r($deleteResult->results);
print "\n---------------\n";
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>