10000 Add Retrieve Data Extension Row using the REST API · SnapLyte/FuelSDK-Python-Wrapper@1bc09e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1bc09e0

Browse files
author
Sebastien.Dangelo
committed
Add Retrieve Data Extension Row using the REST API
1 parent bab412c commit 1bc09e0

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

FuelSDKWrapper.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,32 @@ def complex_filter(left_operand, logical_operator, right_operand):
290290
}
291291

292292

293+
def search_filter_for_rest_call(search_filter):
294+
if 'LeftOperand' in search_filter: # Complex Filter
295+
left_operand = search_filter_for_rest_call(search_filter['LeftOperand'])
296+
logical_operator = search_filter['LogicalOperator']
297+
right_operand = search_filter_for_rest_call(search_filter['RightOperand'])
298+
return "{}%20{}%20{}".format(left_operand, logical_operator, right_operand)
299+
else: # Simple Filter
300+
prop = search_filter['Property']
301+
operator = operator_for_rest_call(search_filter['SimpleOperator'])
302+
value = search_filter.get('Value', search_filter.get('DateValue'))
303+
return "{}%20{}%20'{}'".format(prop, operator, value)
304+
305+
306+
def operator_for_rest_call(operator):
307+
operators = {
308+
'equals': 'eq',
309+
'notEquals': 'neq',
310+
'greaterThan': 'gt',
311+
'greaterThanOrEqual': 'gte',
312+
'lessThan': 'lt',
313+
'lessThanOrEqual': 'lte',
314+
'like': 'like'
315+
}
316+
return operators[operator]
317+
318+
293319
class ET_API:
294320

295321
client = None
@@ -422,6 +448,36 @@ def get_data_extension_columns(self, customer_key, property_list=None):
422448
def get_list_subscriber(self, search_filter=None, property_list=None):
423449
return self.get_objects(ObjectType.LIST_SUBSCRIBER, search_filter, property_list)
424450

451+
def get_data_extension_rows_rest(self, customer_key, search_filter=None, property_list=None, order_by=None, page_size=None, page=None):
452+
headers = {'content-type': 'application/json', 'Authorization': 'Bearer {}'.format(self.client.authToken)}
453+
endpoint = "{}data/v1/customobjectdata/key/{}/rowset?".format(self.client.base_api_url, customer_key)
454+
455+
if search_filter:
456+
endpoint += "&$filter={}".format(search_filter_for_rest_call(search_filter))
457+
458+
if property_list:
459+
endpoint += "&$fields={}".format(",".join(property_list))
460+
461+
if order_by:
462+
endpoint += "&$orderBy={}".format(order_by)
463+
464+
if page_size:
465+
endpoint += "&$pagesize={}".format(page_size)
466+
467+
if page:
468+
endpoint += "&$page={}".format(page)
469+
470+
result = []
471+
r = requests.get(endpoint, headers=headers)
472+
if r.status_code == 200 and r.json()['count']:
473+
result = r.json()['items']
474+
while 'next' in r.json()['links']:
475+
endpoint = '{}data{}'.format(self.client.base_api_url, r.json()['links']['next'])
476+
r = requests.get(endpoint, headers=headers)
477+
if r.status_code == 200 and r.json()['count']:
478+
result += r.json()['items']
479+
return result
480+
425481
def get_data_extension_rows(self, customer_key, search_filter=None, property_list=None):
426482
de_row = FuelSDK.ET_DataExtension_Row()
427483
de_row.auth_stub = self.get_client()

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ values_list = [
148148
["Row3_Value1", "Row3_Value2", "Row3_Value3"]
149149
]
150150
response = api.create_data_extension_rows("DE_Key", keys_list, values_list)
151+
152+
# Retrieve Data Extension Rows via REST API for more advanced parameters
153+
response = api.get_data_extension_rows_rest(
154+
customer_key="DE_CUSTOMER_KEY",
155+
search_filter=complex_filter(
156+
simple_filter("first_name", Operator.EQUALS, "John"),
157+
'AND',
158+
simple_filter("last_name", Operator.EQUALS, "Doe")
159+
),
160+
property_list=["email_address", "first_name", "last_name"],
161+
order_by="first_name ASC,last_name DESC",
162+
page_size=100,
163+
page=5
164+
)
151165
```
152166

153167
### Get More Results
@@ -223,7 +237,7 @@ Python 2.7.x
223237

224238
Libraries:
225239

226-
* FuelSDK>=0.9.3
240+
* Salesforce-FuelSDK>=1.3.0
227241
* PyJWT>=0.1.9
228242
* requests>=2.18.4
229243
* suds>=0.4

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__title__ = 'FuelSDKWrapper'
2-
__version__ = '1.1.3'
2+
__version__ = '1.1.4'
33
__author__ = 'Seb Angel'
44
__license__ = 'MIT'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
readme = f.read()
55

66
setup(
7-
version='1.1.3',
7+
version='1.1.4',
88
name='FuelSDKWrapper',
99
description='Simplify and enhance the FuelSDK for Salesforce Marketing Cloud (ExactTarget)',
1010
long_description=readme,

0 commit comments

Comments
 (0)
0