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!