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 192
/
sample_triggeredsend.py
123 lines (107 loc) · 5.39 KB
/
sample_triggeredsend.py
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
import ET_Client
import uuid
try:
debug = False
stubObj = ET_Client.ET_Client(False, debug)
# Get all TriggeredSendDefinitions
print('>>> Get all TriggeredSendDefinitions')
getTS = ET_Client.ET_TriggeredSend()
getTS.auth_stub = stubObj
getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
getResponse = getTS.get()
print('Retrieve Status: ' + str(getResponse.status))
print('Code: ' + str(getResponse.code))
print('Message: ' + str(getResponse.message))
print('MoreResults: ' + str(getResponse.more_results))
print('Results Count: ' + str(len(getResponse.results)))
#print 'Results: ' + str(getResponse.results)
# Specify the name of a TriggeredSend that was setuprint for testing
# Do not use a production Triggered Send Definition
NameOfTestTS = "TEXTEXT"
# Pause a TriggeredSend
print('>>> Pause a TriggeredSend')
patchTrig = ET_Client.ET_TriggeredSend()
patchTrig.auth_stub = stubObj
patchTrig.props = {"CustomerKey" : NameOfTestTS, "TriggeredSendStatus" :"Inactive"}
patchResponse = patchTrig.patch()
print('Patch Status: ' + str(patchResponse.status))
print('Code: ' + str(patchResponse.code))
print('Message: ' + str(patchResponse.message))
print('Result Count: ' + str(len(patchResponse.results)))
print('Results: ' + str(patchResponse.results))
# Retrieve Single TriggeredSend
print('>>> Retrieve Single TriggeredSend')
getTS = ET_Client.ET_TriggeredSend()
getTS.auth_stub = stubObj
getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
getTS.search_filter = {'Property' : 'CustomerKey','SimpleOperator' : 'equals','Value' : NameOfTestTS}
getResponse = getTS.get()
print('Retrieve Status: ' + str(getResponse.status))
print('Code: ' + str(getResponse.code))
print('Message: ' + str(getResponse.message))
print('MoreResults: ' + str(getResponse.more_results))
print('Results Count: ' + str(len(getResponse.results)))
print('Results: ' + str(getResponse.results))
# Start a TriggeredSend by setting to Active
print('>>> Start a TriggeredSend by setting to Active')
patchTrig = ET_Client.ET_TriggeredSend()
patchTrig.auth_stub = stubObj
patchTrig.props = {"CustomerKey" : NameOfTestTS, "TriggeredSendStatus" :"Active"}
patchResponse = patchTrig.patch()
print('Patch Status: ' + str(patchResponse.status))
print('Code: ' + str(patchResponse.code))
print('Message: ' + str(patchResponse.message))
print('Result Count: ' + str(len(patchResponse.results)))
print('Results: ' + str(patchResponse.results))
# Retrieve Single TriggeredSend After setting back to active
print('>>> Retrieve Single TriggeredSend After setting back to active')
getTS = ET_Client.ET_TriggeredSend()
getTS.auth_stub = stubObj
getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
getTS.search_filter = {'Property' : 'CustomerKey','SimpleOperator' : 'equals','Value' : NameOfTestTS}
getResponse = getTS.get()
print('Retrieve Status: ' + str(getResponse.status))
print('Code: ' + str(getResponse.code))
print('Message: ' + str(getResponse.message))
print('MoreResults: ' + str(getResponse.more_results))
print('Results Count: ' + str(len(getResponse.results)))
print('Results: ' + str(getResponse.results))
# Send an email with TriggeredSend
print('>>> Send an email with TriggeredSend')
sendTrig = ET_Client.ET_TriggeredSend()
sendTrig.auth_stub = stubObj
sendTrig.props = {"CustomerKey" : NameOfTestTS}
sendTrig.subscribers = [{"EmailAddress":"[email protected]", "SubscriberKey" : "[email protected]"}]
sendResponse = sendTrig.send()
print('Send Status: ' + str(sendResponse.status))
print('Code: ' + str(sendResponse.code))
print('Message: ' + str(sendResponse.message))
print('Result Count: ' + str(len(sendResponse.results)))
print('Results: ' + str(sendResponse.results))
# Generate a unique identifier for the TriggeredSend customer key since they cannot be re-used even after deleted
TSNameForCreateThenDelete = str(uuid.uuid4())
# Create a TriggeredSend Definition
print('>>> Create a TriggeredSend Definition')
postTrig = ET_Client.ET_TriggeredSend()
postTrig.auth_stub = stubObj
postTrig.props = {'CustomerKey' : TSNameForCreateThenDelete,'Name' : TSNameForCreateThenDelete, 'Email' : {"ID":"3113962"}, "SendClassification": {"CustomerKey": "2240"}}
postResponse = postTrig.post()
print('Post Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Result Count: ' + str(len(postResponse.results)))
print('Results: ' + str(postResponse.results))
# Delete a TriggeredSend Definition
print('>>> Delete a TriggeredSend Definition ')
deleteTrig = ET_Client.ET_TriggeredSend()
deleteTrig.auth_stub = stubObj
deleteTrig.props = {'CustomerKey' : TSNameForCreateThenDelete}
deleteResponse = deleteTrig.delete()
print('Delete Status: ' + str(deleteResponse.status))
print('Code: ' + str(deleteResponse.code))
print('Message: ' + str(deleteResponse.message))
print('Result Count: ' + str(len(deleteResponse.results)))
print('Results: ' + str(deleteResponse.results))
except Exception as e:
print('Caught exception: ' + e.message)
print(e)