3

I'm trying to send an Email to a List using the Python FuelSDK. Since I also have to control the FromAddress, the documentation seemed to indicate that I needed a EmailSendDefinition rather than the simpler Send object. What I'm struggling with is performing that EmailSendDefinition.

Since the EmailSendDefinition object is not defined in the base FuelSDK-Python, I have added the following code:

class ET_Perform(ET_Constructor):

    def __init__(self, auth_stub, action, options=None, definitions=()):
        auth_stub.refresh_token()

        parsed_options = self.parse_props_into_ws_object(auth_stub, 'PerformOptions', options) if options else None
        parsed_definitions = [self.parse_props_into_ws_object(auth_stub, obj_type, props) for obj_type, props in definitions]

        response = auth_stub.soap_client.service.Perform(parsed_options, action, parsed_definitions)
        if response is not None:
            super(ET_Perform, self).__init__(response)


class ET_EmailSendDefinition(ET_CUDSupport):

    obj_type = 'EmailSendDefinition'

    def perform(self):
        self.obj = ET_Perform(self.auth_stub, 'start', definitions=((self.obj_type, self.props),))
        return self.obj

I then proceed to create an EmailSendDefinition, assigning it a known CustomerKey for later reference:

email_send_def_key = unicode(uuid.uuid4())
email_send_definition = ET_EmailSendDefinition()
email_send_definition.auth_stub = client
email_send_definition.props = {
    'Name': email_send_def_key,
    'CustomerKey': email_send_def_key,
    'Email': {
        'ID': new_email_id
    },
    'SendDefinitionList': [{
        'List': {
            'ID': list_id
        },
        'DataSourceTypeID': 'List'
    }],
    'SendClassification': {
        'CustomerKey': 'Default Commercial'
    }
}

if from_email:
    email_send_definition.props['SenderProfile'] = {
        'FromAddress': from_email
    }

response = email_send_definition.post()

I get a successful response from that call. I then proceed to perform that definition, like so:

email_def = ET_EmailSendDefinition()
email_def.auth_stub = client
email_def.props = {
    'CustomerKey': email_send_def_key
}
response = email_def.perform()

This, however, gets me a 500 Internal Server Error as a response. So instead, I tried to create a PerformRequestMsg object. Here's the code I used:

class ET_PerformRequestMsg(FuelSDK.ET_CUDSupport):
    def __init__(self):
        super(ET_PerformRequestMsg, self).__init__()
        self.obj_type = 'PerformRequestMsg'

email_def = ET_EmailSendDefinition()
email_def.auth_stub = client
email_def.props = {
    'CustomerKey': email_send_def_key
}

msg = ET_PerformRequestMsg()
msg.auth_stub = client
msg.props = {
    'Action': 'start',
    'Definitions': [email_def]
}
response = msg.post()

This failed as well, complaining of not being able to find the type APIObject, which appears to be pretty well defined in the WSDL. This alternative also failed:

msg = ET_PerformRequestMsg()
msg.auth_stub = client
msg.props = {
    'Action': 'start',
    'Definitions': [{
        'EmailSendDefinition' : {
            'CustomerKey': email_send_def_key
        }
    }]
}
response = msg.post()

It raised errors about type EmailSendDefinition not being found as well.

Am I going about this the wrong way, or am I missing something crucial here?

Thanks in advance,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.