0

I've been trying (unsuccessfully) to use the FuelSDK to schedule an email to be sent via the FuelSDK (C#). I've followed various examples from the documentation but so far nothing works.

My first attempt is as follows. In the following code, I'm creating an ET_EmailSendDefinition object. The code that calls this method then invokes the Post() method on the ET_EmailSendDefinition object that it returns:

    public ET_EmailSendDefinition CreateEmailSendDefinition(int businessGroupId, int emailId, string newsletterName, DateTime sendDateTime)
    {
        var sendClassification = GetSendClassification();
        if (sendClassification == null)
            throw new ApplicationException("Couldn't find default commercial send classification.");

        var def = new ET_EmailSendDefinition
        {
            Name = newsletterName,
            DeliveryScheduledTime = sendDateTime,
            DeliveryScheduledTimeSpecified = true,
            Client = new ClientID { ID = businessGroupId, IDSpecified = true },
            Email = new Email { ID = emailId, IDSpecified = true },
            AuthStub = new ET_Client(_clientAuth),
            SendClassification = sendClassification, 
            SendDefinitionList = new[]
            {
                //TODO: Get correct data filter
                new SendDefinitionList
                {
                    DataSourceTypeID = DataSourceTypeEnum.FilterDefinition,
                    FilterDefinition = new FilterDefinition { ObjectID = "0c747904-f520-49c4-8f29-d397ae06a238" },
                    DataSourceTypeIDSpecified = true,
                    SendDefinitionListType = SendDefinitionListTypeEnum.SourceList,
                    SendDefinitionListTypeSpecified = true

                }
            }
        };

        return def;
    }

Calling the Post() method on the object returned by the above code results in an exception during serialization. The inner exception reveals that "The type FuelSDK.ET_SendClassification was not expected." But the funny thing is that I'm providing a SendClassification, NOT an ET_SendClassification. When I comment out the line that sets the SendClassification, I get an exception about ET_SendDefinitionList being unexpected, even though I'm not using an object of THAT type either.

I then tried a different approach which creates the object and attempts the post in a single method (I was going to clean it up later to separate the steps into different methods, but since it hasn't worked correctly so far, I haven't cleaned anything up yet!). Here's Approach Two (lifted almost verbatim from example code on the API site):

    public void ScheduleEmail(int businessGroupId, int emailId, string newsletterName, DateTime sendDateTime)
    {
        EmailSendDefinition definition = new EmailSendDefinition();

        definition.Name = newsletterName;
        Email email = new Email();
        email.ID = emailId;
        email.IDSpecified = true;

        definition.Email = email; 
        definition.SendClassification = GetSendClassification(); 

        definition.SendDefinitionList = new SendDefinitionList[1];
        definition.SendDefinitionList[0] = new SendDefinitionList();

        definition.SendDefinitionList[0].CustomObjectID = "b4c3e257-7424-e311-85d1-ac162db19804";
        definition.SendDefinitionList[0].DataSourceTypeID = DataSourceTypeEnum.CustomObject;
        definition.SendDefinitionList[0].DataSourceTypeIDSpecified = true;

        definition.IsMultipart = true;
        definition.IsMultipartSpecified = true;
        APIObject[] createObjects = { definition };
        String requestId = null;
        String overallStatus = null;

        var client = new ET_Client(_clientAuth);
        client.soapclient.ClientCredentials.UserName.UserName = _username;
        client.soapclient.ClientCredentials.UserName.Password = _password;

        CreateResult[] results =
            client.soapclient.Create(new CreateOptions(), createObjects, out requestId, out overallStatus);
    }

When I check the results, I find that the call was unsuccessful, providing the ever-so-helpful error message "Exception occurred during [CreateEmailSendDefinition] ErrorID = 87433421". I got in touch with tech support, who were able to provide me with more information that was logged on their end: an inner exception that read "Invalid argument for the equals operator. Filter array cannot be null."

I'm obviously doing something wrong here. What I want to do is tell the system to send out the specified email to a filtered group of recipients on the day provided. Can anybody offer any help? Thanks!

0

The FuelSDK doesn't include all available Marketing Cloud API functionality. In order to leverage the Schedule method within the SOAP API, that API would need to be accessed outside of the SDK by going directly against the SOAP service. Example available at:

https://help.exacttarget.com/en/technical_library/web_service_guide/technical_articles/scheduling_an_email_send_definition/

  • Thanks Mac, but the example shown in the link provided seems to be code that implements a recurring email. I'm looking to schedule a one-time emailing of a newsletter. I tried to set the ScheduleDefinition RecurrenceType to something that doesn't recurr, but there's no enum value for that. Could you point me in the right direction? Thanks for your help. :) – Alan Feb 8 '16 at 20:27
  • As long as the Occurrences property is set to 1 then it will only run once. – Mac Feb 9 '16 at 0:21
  • Thanks Mac. I followed the example code at the link above. The only difference was that I added a single line of code to specify which email I'm sending. However, this resulted in "Exception occurred during [ScheduleEmailSendDefinition] ErrorID: 1375426187". Any idea what I'm doing wrong? The line of code I added was definition.Email = new Email { ID = emailId, IDSpecified = true };. Other than that single line, my code is identical to the sample. – Alan Feb 9 '16 at 19:40
  • The EmailSendDefinition object that specifies the email to send has to be created prior to calling Schedule or Perform. Schedule and Perform simply take the details from the existing definition (which is referenced by CustomerKey or ObjectID) and uses that for the send. It isn't possible to pass values for Email address to override the values saved on the definition. – Mac Feb 10 '16 at 19:03
  • Thanks Mac, but the call to create the EmailSendDefinition results in the error that was the reason I posted this question originally (see the 2nd code example in my original post). Sorry, not trying to be difficult -- just stuck. Thanks for your (repeated) attempts to try to help me! – Alan Feb 12 '16 at 18:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.