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_dataextension.py
203 lines (181 loc) · 8.32 KB
/
sample_dataextension.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
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
import ET_Client
try:
debug = False
stubObj = ET_Client.ET_Client(False, debug)
# Get all of the DataExtensions in an Account
print('>>> Get all of the DataExtensions in an Account')
de = ET_Client.ET_DataExtension()
de.auth_stub = stubObj
de.props = ["CustomerKey", "Name"]
getResponse = de.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
#print 'Results: ' + str(getResponse.results)
# Get all of the DataExtensions in an Account belonging to a specific sub account
print('>>> Get all of the DataExtensions in an Account belonging to a specific sub account')
de = ET_Client.ET_DataExtension()
de.auth_stub = stubObj
de.props = ["CustomerKey", "Name"]
de.options = {"Client": {"ID": "1234567"}}
getResponse = de.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
#print 'Results: ' + str(getResponse.results)
# 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
NameOfDE = "ThisWillBeDeleted-Test"
# Create Data Extension
print('>>> Create Data Extension')
de2 = ET_Client.ET_DataExtension()
de2.auth_stub = stubObj
de2.props = {"Name" : NameOfDE,"CustomerKey" : NameOfDE}
de2.columns = [{"Name" : "Name", "FieldType" : "Text", "IsPrimaryKey" : "true", "MaxLength" : "100", "IsRequired" : "true"},{"Name" : "OtherField", "FieldType" : "Text"}]
postResponse = de2.post()
print('Post Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Results: ' + str(postResponse.results))
# Update DE to add new field
print('>>> Update DE to add new field')
de3 = ET_Client.ET_DataExtension()
de3.auth_stub = stubObj
de3.props = {"Name" : NameOfDE,"CustomerKey" : NameOfDE}
de3.columns = [{"Name" : "AddedField", "FieldType" : "Text"}]
patchResponse = de3.patch()
print('Patch Status: ' + str(patchResponse.status))
print('Code: ' + str(patchResponse.code))
print('Message: ' + str(patchResponse.message))
print('Results: ' + str(patchResponse.results))
# Retrieve all columns for data extension
print('>>> Retrieve all columns for data extension ')
myDEColumn = ET_Client.ET_DataExtension_Column()
myDEColumn.auth_stub = stubObj
myDEColumn.props = ["Name"]
myDEColumn.search_filter = {'Property' : 'CustomerKey','SimpleOperator' : 'equals','Value' : NameOfDE}
getResponse = myDEColumn.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
print('Results: ' + str(getResponse.results))
# Add a row to a data extension (using CustomerKey)
print('>>> Add a row to a data extension')
de4 = ET_Client.ET_DataExtension_Row()
de4.CustomerKey = NameOfDE;
de4.auth_stub = stubObj
de4.props = {"Name" : "MAC3", "OtherField" : "Text3"}
postResponse = de4.post()
print('Post Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Results: ' + str(postResponse.results))
# Add a row to a data extension (Using Name)
print('>>> Add a row to a data extension')
de4 = ET_Client.ET_DataExtension_Row()
de4.auth_stub = stubObj
de4.Name = NameOfDE
de4.props = {"Name" : "MAC4", "OtherField" : "Text3"}
postResponse = de4.post()
print('Post Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Results: ' + str(postResponse.results))
# Retrieve all rows
print('>>> Retrieve all rows')
row = ET_Client.ET_DataExtension_Row()
row.auth_stub = stubObj
row.CustomerKey = NameOfDE
row.props = ["Name","OtherField"]
getResponse = row.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
print('Results: ' + str(getResponse.results))
# Update a row in a data extension
print('>>> Update a row in a data extension')
de4 = ET_Client.ET_DataExtension_Row()
de4.auth_stub = stubObj
de4.CustomerKey = NameOfDE
de4.props = {"Name" : "MAC3", "OtherField" : "UPDATED!"}
postResponse = de4.patch()
print('Patch Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Results: ' + str(postResponse.results))
# Retrieve only updated row
print('>>> Retrieve only updated row')
row = ET_Client.ET_DataExtension_Row()
row.auth_stub = stubObj
row.CustomerKey = NameOfDE
row.props = ["Name","OtherField"]
row.search_filter = {'Property' : 'Name','SimpleOperator' : 'equals','Value' : 'MAC3'}
getResponse = row.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
print('Results: ' + str(getResponse.results))
# Delete a row from a data extension
print('>>> Delete a row from a data extension')
de4 = ET_Client.ET_DataExtension_Row()
de4.auth_stub = stubObj
de4.CustomerKey = NameOfDE
de4.props = {"Name" : "MAC3"}
deleteResponse = de4.delete()
print('Delete Status: ' + str(deleteResponse.status))
print('Code: ' + str(deleteResponse.code))
print('Message: ' + str(deleteResponse.message))
print('Results: ' + str(deleteResponse.results))
# Delete a Data Extension
print('>>> Delete a Data Extension')
de5 = ET_Client.ET_DataExtension()
de5.auth_stub = stubObj
de5.props = {"Name" : NameOfDE,"CustomerKey" : NameOfDE}
delResponse = de5.delete()
print('Delete Status: ' + str(delResponse.status))
print('Code: ' + str(delResponse.code))
print('Message: ' + str(delResponse.message))
print('Results: ' + str(delResponse.results))
# Retrieve lots of rows with moreResults
print('>>> Retrieve lots of rows with moreResults')
row = ET_Client.ET_DataExtension_Row()
row.auth_stub = stubObj
row.Name = "zipstolong"
row.props = ["zip","latitude","longitude"]
getResponse = row.get()
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))
print('Results Length: ' + str(len(getResponse.results)))
#print 'Results: ' + str(getResponse.results)
while getResponse.more_results:
print('>>> Continue Retrieve lots of rows with moreResults')
getResponse = row.getMoreResults()
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))
print('Results Length: ' + str(len(getResponse.results)))
except Exception as e:
print('Caught exception: ' + str(e.message))
print(e)