I've been tasked with using python to pull event data from marketing cloud into a SQL database. I can get a print output with getResponse = getBounceEvent.get(), then print(getResponse.results). But the format is strange:

   Client = 
         ID = client_id_here
   PartnerKey = None
   ObjectID = None
   SendID = 4016
   SubscriberKey = "subscriber_key_here"
   EventDate = 2021-05-12 12:53:38.780000
   EventType = "OtherBounce"
   TriggeredSendDefinitionObjectID = None
   BatchID = 4
 }, (BounceEvent){
   Client = 
etc, etc

I gather from the square brackets that it's ultimately a list, but what's inside it is not-quite-json. Any ideas how I can get this into a dataframe?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Jan 6, 2023 at 4:13
  • It seems pretty clear that I want the contents of the API result into a pandas dataframe. Commented Jan 8, 2023 at 20:54

2 Answers 2


This was resolved by having a function that iterates over the keys and values and places them in a json object

def sfmc_to_json(obj=None, object_name='element'):
    """Take an object and drop it into JSON, the object_name parameter is used
        to prefex the JSON package"""
    if isinstance(obj, type({})):
        data = obj["items"]
    elif isinstance(obj, type([])):
        data = _list_of_suds_to_json(object_name, obj)
        data = _suds_to_json(obj)
    key_prefix = (object_name+"s").lower()
    return { key_prefix : data }
    #return data

def _recursive_asdict(d):
    """Convert Suds object (What API returns) into serializable format."""
    out = {}
    for k, v in _asdict(d).items():
        if hasattr(v, "__keylist__"):
            out[k] = _recursive_asdict(v)
        elif isinstance(v, type([])):
            out[k] = []
            for item in v:
                if hasattr(item, "__keylist__"):
            out[k] = v
    return out

The documentation states the same format. This sample might help your use case. Extract and save the results into the list and then convert it into the pandas dataframe.

  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Commented Jan 14, 2023 at 18:09
  • Why would you say "convert the list into a pandas dataframe" when converting the list into a pandas dataframe was the original problem? Commented Jan 15, 2023 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .