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
/
Copy pathsample_campaign.py
167 lines (149 loc) · 7.37 KB
/
sample_campaign.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
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
import ET_Client
try:
debug = False
stubObj = ET_Client.ET_Client(False, debug)
# In order for this sample to run, it needs to have an asset that it can associate the campaign to
ExampleAssetType = "Email"
ExampleAssetItemID = "32798"
# Retrieve all Campaigns
print( '>>> Retrieve all Campaigns')
getCamp = ET_Client.ET_Campaign()
getCamp.auth_stub = stubObj
getResponse = getCamp.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'MoreResults: ' + str(getResponse.more_results))
if 'count' in getResponse.results:
print( 'Results(Items) Length: ' + str(len(getResponse.results['items'])))
# print( 'Results(Items): ' + str(getResponse.results)
print( '-----------------------------')
while getResponse.more_results:
print( '>>> Continue Retrieve all Campaigns with GetMoreResults')
getResponse = getCamp.getMoreResults()
print( str(getResponse))
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'MoreResults: ' + str(getResponse.more_results))
print( 'RequestID: ' + str(getResponse.request_id))
if 'count' in getResponse.results:
print( 'Results(Items) Length: ' + str(len(getResponse.results['items'])))
# Create a new Campaign
print( '>>> Create a new Campaign')
postCamp = ET_Client.ET_Campaign()
postCamp.auth_stub = stubObj
postCamp.props = {"name" : "PythonSDKCreatedForTest", "description": "PythonSDKCreatedForTest", "color":"FF9933", "favorite":"false"}
postResponse = postCamp.post()
print( 'Post Status: ' + str(postResponse.status))
print( 'Code: ' + str(postResponse.code))
print( 'Message: ' + str(postResponse.message))
print( 'Results: ' + str(postResponse.results))
print( '-----------------------------')
if postResponse.status:
IDOfpostCampaign = postResponse.results['id']
# Retrieve the new Campaign
print( '>>> Retrieve the new Campaign')
getCamp = ET_Client.ET_Campaign()
getCamp.auth_stub = stubObj
getCamp.props = {"id" : IDOfpostCampaign}
getResponse = getCamp.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'Results: ' + str(getResponse.results))
print( '-----------------------------')
# Update the new Campaign
print( '>>> Update the new Campaign')
patchCamp = ET_Client.ET_Campaign()
patchCamp.auth_stub = stubObj
patchCamp.props = {"id": IDOfpostCampaign, "name" : "PythonSDKCreated-Updated!"}
postResponse = patchCamp.patch()
print( 'Patch Status: ' + str(postResponse.status))
print( 'Code: ' + str(postResponse.code))
print( 'Message: ' + str(postResponse.message))
print( 'Results: ' + str(postResponse.results))
print( '-----------------------------')
# Retrieve the updated Campaign
print( '>>> Retrieve the updated Campaign')
getCamp = ET_Client.ET_Campaign()
getCamp.auth_stub = stubObj
getCamp.props = {"id" : IDOfpostCampaign}
getResponse = getCamp.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'Results: ' + str(getResponse.results))
print( '-----------------------------')
# Create a new Campaign Asset
print( '>>> Create a new Campaign Asset')
postCampAsset = ET_Client.ET_Campaign_Asset()
postCampAsset.auth_stub = stubObj
postCampAsset.props = {"id" : IDOfpostCampaign, "ids": [ExampleAssetItemID], "type": ExampleAssetType}
postResponse = postCampAsset.post()
print( 'Post Status: ' + str(postResponse.status))
print( 'Code: ' + str(postResponse.code))
print( 'Message: ' + str(postResponse.message))
print( 'Results: ' + str(postResponse.results))
print( '-----------------------------')
if not isinstance(postResponse.results, list) :
quit()
IDOfpostCampaignAsset = postResponse.results[0]['id']
# Retrieve all Campaign Asset for a campaign
print( '>>> Retrieve all Campaign Asset for a Campaign')
getCampAsset = ET_Client.ET_Campaign_Asset()
getCampAsset.auth_stub = stubObj
getCampAsset.props = {"id" : IDOfpostCampaign}
getResponse = getCampAsset.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'Results: ' + str(getResponse.results))
print( '-----------------------------')
# Retrieve a single new Campaign Asset
print( '>>> Retrieve a single new Campaign Asset')
getCampAsset = ET_Client.ET_Campaign_Asset()
getCampAsset.auth_stub = stubObj
getCampAsset.props = {"id" : IDOfpostCampaign, "assetId" : IDOfpostCampaignAsset}
getResponse = getCampAsset.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'Results: ' + str(getResponse.results))
print( '-----------------------------')
# Delete the new Campaign Asset
print( '>>> Delete the new Campaign Asset')
deleteCampAsset = ET_Client.ET_Campaign_Asset()
deleteCampAsset.auth_stub = stubObj
deleteCampAsset.props = {"id" : IDOfpostCampaign, "assetId": IDOfpostCampaignAsset}
deleteResponse = deleteCampAsset.delete()
print( 'Delete Status: ' + str(deleteResponse.status))
print( 'Code: ' + str(deleteResponse.code))
print( 'Message: ' + str(deleteResponse.message))
print( 'Results: ' + str(deleteResponse.results))
print( '-----------------------------')
# Get a single a new Campaign Asset to confirm deletion
print( '>>> Get a single a new Campaign Asset to confirm deletion')
getCampAsset = ET_Client.ET_Campaign_Asset()
getCampAsset.auth_stub = stubObj
getCampAsset.props = {"id" : IDOfpostCampaign, "assetId" : IDOfpostCampaignAsset}
getResponse = getCampAsset.get()
print( 'Retrieve Status: ' + str(getResponse.status))
print( 'Code: ' + str(getResponse.code))
print( 'Message: ' + str(getResponse.message))
print( 'Results: ' + str(getResponse.results))
print( '-----------------------------')
# Delete the new Campaign
print( '>>> Delete the new Campaign')
deleteCamp = ET_Client.ET_Campaign()
deleteCamp.auth_stub = stubObj
deleteCamp.props = {"id": IDOfpostCampaign}
deleteResponse = deleteCamp.delete()
print( 'Delete Status: ' + str(deleteResponse.status))
print( 'Code: ' + str(deleteResponse.code))
print( 'Message: ' + str(deleteResponse.message))
print( 'Results: ' + str(deleteResponse.results))
print( '-----------------------------')
except Exception as e:
print( 'Caught exception: ' + e.message)
print( e )