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-triggeredsend.php
executable file
·138 lines (121 loc) · 5.54 KB
/
sample-triggeredsend.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
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_TriggeredSend;
try {
$myclient = new ET_Client();
//Triggered Send Testing
print_r("Get all TriggeredSendDefinitions \n");
$trigger = new ET_TriggeredSend();
$trigger->authStub = $myclient;
$trigger->props = array("CustomerKey", "Name", "TriggeredSendStatus");
$getResult = $trigger->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Result Count: '.count($getResult->results)."\n";
//print 'Results: '."\n";
//print_r($getResult->results);
print "\n---------------\n";
// Specify the name of a TriggeredSend that was setup for testing
// Do not use a production Triggered Send Definition
$NameOfTestTS = "TEXTEXT";
// Pause a TriggeredSend
print_r("Pause a TriggeredSend \n");
$patchTrig = new ET_TriggeredSend();
$patchTrig->authStub = $myclient;
$patchTrig->props = array('CustomerKey' => $NameOfTestTS, 'TriggeredSendStatus' => 'Inactive' );
$patchResult = $patchTrig->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";
// Retrieve Single TriggeredSend
print_r("Retrieve Single TriggeredSend \n");
$trigger = new ET_TriggeredSend();
$trigger->authStub = $myclient;
$trigger->props = array("CustomerKey", "Name", "TriggeredSendStatus");
$trigger->filter = array('Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => $NameOfTestTS);
$getResult = $trigger->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Result Count: '.count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Start a TriggeredSend by setting to Active
print_r("Start a TriggeredSend by setting to Active \n");
$patchTrig = new ET_TriggeredSend();
$patchTrig->authStub = $myclient;
$patchTrig->props = array('CustomerKey' => 'TEXTEXT', 'TriggeredSendStatus' => 'Active', 'RefreshContent'=>'true' );
$patchResult = $patchTrig->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";
// Retrieve Single TriggeredSend After setting back to active
print_r("Retrieve Single TriggeredSend After setting back to active\n");
$trigger = new ET_TriggeredSend();
$trigger->authStub = $myclient;
$trigger->props = array("CustomerKey", "Name", "TriggeredSendStatus");
$trigger->filter = array('Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => 'TEXTEXT');
$getResult = $trigger->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print 'Result Count: '.count($getResult->results)."\n";
print 'Results: '."\n";
print_r($getResult->results);
print "\n---------------\n";
// Send an email with TriggeredSend
print_r("Send an email using a triggered send \n");
$sendTrigger = new ET_TriggeredSend();
$sendTrigger->props = array('CustomerKey' => 'TEXTEXT');
$sendTrigger->authStub = $myclient;
$sendTrigger->subscribers = array(array("EmailAddress" => "testing@bh.exacttarget.com", "SubscriberKey" => "testing@bh.exacttarget.com"));
$sendResult = $sendTrigger->send();
print_r('Send Status: '.($sendResult->status ? 'true' : 'false')."\n");
print 'Code: '.$sendResult->code."\n";
print 'Message: '.$sendResult->message."\n";
print 'Results: '."\n";
print_r($sendResult->results);
print "\n---------------\n";
// Generate a unique identifier for the TriggeredSend customer key since they cannot be re-used even after deleted
$TSNameForCreateThenDelete = uniqid();
// Create a TriggeredSend Definition
print_r("Create a TriggeredSend Definition \n");
$postTrig = new ET_TriggeredSend();
$postTrig->authStub = $myclient;
$postTrig->props = array('CustomerKey' => $TSNameForCreateThenDelete,'Name' => $TSNameForCreateThenDelete, 'Email' => array("ID"=>"90022"), "SendClassification"=> array("ObjectID"=> "7d949116-8b40-e711-80d3-1402ec6b94d5") );
$postResult = $postTrig->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";
// Delete a TriggeredSend Definition
print_r("Delete a TriggeredSend Definition \n");
$deleteTrig = new ET_TriggeredSend();
$deleteTrig->authStub = $myclient;
$deleteTrig->props = array('CustomerKey' => $TSNameForCreateThenDelete);
$deleteResult = $deleteTrig->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";
}
?>