Advertisement
lengthy_preamble

sf_to_dataframe

Dec 29th, 2022
1,859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import FuelSDK
  2. import ET_Client
  3. import pandas as pd
  4.  
  5.  
  6. #define local variables
  7.  
  8. clientid= 'my_client_id_code'
  9. clientsecret='my_client_secret_code'
  10. subdomain = 'mcx1k2thcht5qzdsm6962p8ln2c8'
  11. auth_base_url = f'https://{subdomain}.auth.marketingcloudapis.com/'
  12. rest_url = f'https://{subdomain}.rest.marketingcloudapis.com/'
  13. soap_url=f'https://{subdomain}.soap.marketingcloudapis.com/'
  14.  
  15.  
  16. #Passing config as a parameter to ET_Client constructor:
  17.  
  18. myClient = FuelSDK.ET_Client(True, False,
  19. {'clientid': clientid,
  20. 'clientsecret': clientsecret,
  21. 'useOAuth2Authentication': 'True',
  22. 'authenticationurl': auth_base_url,
  23. 'applicationType': 'server',
  24. 'baseapiurl': rest_url,
  25. 'soapendpoint': soap_url})
  26.  
  27.  
  28. # Create an instance of the object type we want to work with:
  29.  
  30. list = FuelSDK.ET_List()
  31.  
  32.  
  33. # Associate the ET_Client- object using the auth_stub property:
  34.  
  35. list.auth_stub = myClient
  36.  
  37.  
  38. # Utilize one of the ET_List methods:
  39.  
  40. response = list.get()
  41.  
  42.  
  43. # Print out the results for viewing
  44. print('Post Status: ' + str(response.status))
  45. print('Code: ' + str(response.code))
  46. print('Message: ' + str(response.message))
  47. print('Result Count: ' + str(len(response.results)))
  48.  
  49. # print('Results: ' + str(response.results))
  50.  
  51. debug = False
  52. stubObj = ET_Client(False, False, params={'clientid': clientid,
  53.                                                    'clientsecret': clientsecret})
  54. getBounceEvent = ET_Client.ET_BounceEvent()
  55. getBounceEvent.auth_stub = stubObj
  56. getBounceEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
  57. getBounceEvent.search_filter = {'Property' : 'EventDate', 'SimpleOperator' : 'greaterThan', 'DateValue' : retrieveDate}
  58. getResponse = getBounceEvent.get()
  59.  
  60.  
  61. #define dataframe to read response into
  62.  
  63. df=pd.DataFrame(getBounceEvent.props)
  64.  
  65.  
  66. #load data into csv data file
  67.  
  68. df.to_csv('salesforce_marketing_cloud_sample.csv', index=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement