Created
April 18, 2018 23:18
-
-
Save mshamma/df502e569d87876b8a0c0d35e36632f5 to your computer and use it in GitHub Desktop.
Marketing Cloud Data Extension Details with Columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Django Management Commands: https://docs.djangoproject.com/en/2.0/howto/custom-management-commands/
Fuel-SDK: https://github.com/salesforce-marketingcloud/FuelSDK-Python