Skip to content

Instantly share code, notes, and snippets.

@mshamma
Created April 18, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshamma/df502e569d87876b8a0c0d35e36632f5 to your computer and use it in GitHub Desktop.
Save mshamma/df502e569d87876b8a0c0d35e36632f5 to your computer and use it in GitHub Desktop.
Marketing Cloud Data Extension Details with Columns
from django.core.management.base import BaseCommand
from FuelSDK import ET_Client, ET_DataExtension, ET_DataExtension_Column
class Command(BaseCommand):
help = 'Queries data extensions (including columns) per Business Unit from Marketing Cloud'
client_id = 'xxxx'
clientsecret = 'xxxxx'
def add_arguments(self, parser):
pass
def handle(self, *args, **options):
try:
stub_obj = ET_Client(False, False, params={'clientid': client_id,
'clientsecret': client_secret})
de = ET_DataExtension()
de.auth_stub = stub_obj
de.props = ["CustomerKey","Name"]
de.search_filter = {'Property': 'Name', 'SimpleOperator': 'like', 'Value': 'test'}
de_res = de.get()
de_list = []
for ext in de_res.results:
de_list.append(ext.CustomerKey)
# columns
for x in de_list:
stub_obj = ET_Client(False, False,
params={
'clientid': client_id,
'clientsecret': client_secret})
de_col_req = ET_DataExtension_Column()
de_col_req.auth_stub = stub_obj
de_col_req.props = ["CustomerKey"]
de_col_req.search_filter = {'Property': 'CustomerKey',
'SimpleOperator': 'like',
'Value': x}
de_col_res = de_col_req.get()
de_cols_added = []
for res_item in de_col_res.results:
print(res_item)
except Exception as e:
print('Caught exception: ' + str(e.message))
print(e)
@mshamma
Copy link
Author

mshamma commented Apr 18, 2018

This is a Django management command script that queries data extensions and their columns using the Fuel-SDK. It has been tested successfully on Python 3.6. Just add this to your requirements.txt

Salesforce-FuelSDK==1.0.1
suds-jurko==0.6

Django Management Commands: https://docs.djangoproject.com/en/2.0/howto/custom-management-commands/
Fuel-SDK: https://github.com/salesforce-marketingcloud/FuelSDK-Python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment