void GetRecipients() { Campaign campaign = new Campaign(campaignID); try { List<CampaignRecipient> recipients = new List<CampaignRecipient>(); PagedCollection<CampaignRecipient> firstPage = campaign.Recipients(1, 50, "email", "ASC"); recipients.AddRange(firstPage.Results); if (firstPage.NumberOfPages > 1) for (int pageNumber = 2; pageNumber <= firstPage.NumberOfPages; pageNumber++) { PagedCollection<CampaignRecipient> subsequentPage = campaign.Recipients(pageNumber, 50, "email", "ASC"); recipients.AddRange(subsequentPage.Results); } foreach (CampaignRecipient recipient in recipients) Console.WriteLine(recipient.EmailAddress); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { // handle some other failure } }
public string CreateCustomField( string fieldName, CustomFieldDataType dataType, List<string> options) { return CreateCustomField(fieldName, dataType, options, true); }
public string CreateWebhook(List<string> events, string url, string payloadFormat) { string json = HttpHelper.Post(string.Format("/lists/{0}/webhooks.json", _listID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "Events", events }, { "Url", url }, { "PayloadFormat", payloadFormat } }) ); return JavaScriptConvert.DeserializeObject<string>(json); }
public static string Create(string clientID, string subject, string name, string fromName, string fromEmail, string replyTo, string htmlUrl, string textUrl, List<string> listIDs, List<string> segmentIDs) { string json = HttpHelper.Post(string.Format("/campaigns/{0}.json", clientID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "Subject", subject }, { "Name", name }, { "FromName", fromName}, { "FromEmail", fromEmail }, { "ReplyTo", replyTo }, { "HtmlUrl", htmlUrl }, { "TextUrl", textUrl }, { "ListIDs", listIDs }, { "SegmentIDs", segmentIDs } }) ); return JavaScriptConvert.DeserializeObject<string>(json); }
public BulkImportResults Import(List<SubscriberDetail> subscribers, bool resubscribe) { List<object> reworkedSusbcribers = new List<object>(); string json = ""; foreach (SubscriberDetail subscriber in subscribers) { Dictionary<string, object> subscriberWithoutDate = new Dictionary<string, object>() { { "EmailAddress", subscriber.EmailAddress }, { "Name", subscriber.Name }, { "CustomFields", subscriber.CustomFields } }; reworkedSusbcribers.Add(subscriberWithoutDate); } try { json = HttpHelper.Post(string.Format("/subscribers/{0}/import.json", ListID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "Subscribers", reworkedSusbcribers }, { "Resubscribe", resubscribe } } )); } catch (CreatesendException ex) { if (!ex.Data.Contains("ErrorResult") && ex.Data.Contains("ErrorResponse")) { ErrorResult<BulkImportResults> result = JavaScriptConvert.DeserializeObject<ErrorResult<BulkImportResults>>(ex.Data["ErrorResponse"].ToString()); ex.Data.Add("ErrorResult", result); } else if(ex.Data.Contains("ErrorResult")) { ErrorResult<BulkImportResults> result = new ErrorResult<BulkImportResults>((ErrorResult)ex.Data["ErrorResult"]); ex.Data["ErrorResult"] = result; } throw ex; } return JavaScriptConvert.DeserializeObject<BulkImportResults>(json); }
public string Add(string emailAddress, string name, List<SubscriberCustomField> customFields, bool resubscribe) { string json = HttpHelper.Post(string.Format("/subscribers/{0}.json", ListID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "EmailAddress", emailAddress }, { "Name", name }, { "CustomFields", customFields }, { "Resubscribe", resubscribe } } )); return JavaScriptConvert.DeserializeObject<string>(json); }
void GetActiveSubscribers() { List list = new List(listID); try { List<SubscriberDetail> allSubscribers = new List<SubscriberDetail>(); //get the first page, with an old date to signify entire list PagedCollection<SubscriberDetail> firstPage = list.Active(new DateTime(1900, 1, 1), 1, 50, "Email", "ASC"); allSubscribers.AddRange(firstPage.Results); if(firstPage.NumberOfPages > 1) for (int pageNumber = 2; pageNumber <= firstPage.NumberOfPages; pageNumber++) { PagedCollection<SubscriberDetail> subsequentPage = list.Active(new DateTime(1900, 1, 1), pageNumber, 50, "Email", "ASC"); allSubscribers.AddRange(subsequentPage.Results); } //we can now do whatever with every subscriber foreach(SubscriberDetail subscriberDetail in allSubscribers) Console.WriteLine(subscriberDetail.EmailAddress); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { //handle some other failure } }
public string CreateCustomField(string fieldName, CustomFieldDataType dataType, List<string> options) { string json = HttpHelper.Post(string.Format("/lists/{0}/customfields.json", _listID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "FieldName", fieldName }, { "DataType", dataType.ToString() }, { "Options", options } }) ); return JavaScriptConvert.DeserializeObject<string>(json); }
void AddWithCustomFields() { Subscriber subscriber = new Subscriber(listID); try { List<SubscriberCustomField> customFields = new List<SubscriberCustomField>(); customFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey", Value = "Value" }); customFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey2", Value = "Value2" }); string newSubscriberID = subscriber.Add("*****@*****.**", "Test Name", customFields, false); Console.WriteLine(newSubscriberID); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { // Handle some other failure Console.WriteLine(ex.ToString()); } }
public static List<Subscriber> MapList(List<SubscriberDetail> subscribers) { var coreSubscriber = new List<Subscriber>(); foreach (var subscriber in subscribers) { coreSubscriber.Add(Map(subscriber)); } return coreSubscriber; }
public void AddRule(string subject, List<string> clauses) { HttpHelper.Post<Dictionary<string, object>, string>( string.Format("/segments/{0}/rules.json", SegmentID), null, new Dictionary<string, object>() { { "Subject", subject }, { "Clauses", clauses } }); }
public string CreateCustomField(string fieldName, CustomFieldDataType dataType, List<string> options) { return HttpHelper.Post<Dictionary<string, object>, string>( string.Format("/lists/{0}/customfields.json", ListID), null, new Dictionary<string, object>() { { "FieldName", fieldName }, { "DataType", dataType.ToString() }, { "Options", options } }); }
public string CreateWebhook(List<string> events, string url, string payloadFormat) { return HttpHelper.Post<Dictionary<string, object>, string>( string.Format("/lists/{0}/webhooks.json", ListID), null, new Dictionary<string, object>() { { "Events", events }, { "Url", url }, { "PayloadFormat", payloadFormat } }); }
public string Add(string emailAddress, string name, List<SubscriberCustomField> customFields, bool resubscribe) { return HttpHelper.Post<Dictionary<string, object>, string>( string.Format("/subscribers/{0}.json", ListID), null, new Dictionary<string, object>() { { "EmailAddress", emailAddress }, { "Name", name }, { "CustomFields", customFields }, { "Resubscribe", resubscribe } }); }
void BatchAdd() { Subscriber subscriber = new Subscriber(listID); List<SubscriberDetail> newSubscribers = new List<SubscriberDetail>(); SubscriberDetail subscriber1 = new SubscriberDetail("*****@*****.**", "Test Person 1", new List<SubscriberCustomField>()); subscriber1.CustomFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey", Value = "Value" }); subscriber1.CustomFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey2", Value = "Value2" }); newSubscribers.Add(subscriber1); SubscriberDetail subscriber2 = new SubscriberDetail("*****@*****.**", "Test Person 2", new List<SubscriberCustomField>()); subscriber2.CustomFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey", Value = "Value3" }); subscriber2.CustomFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey2", Value = "Value4" }); newSubscribers.Add(subscriber2); try { BulkImportResults results = subscriber.Import(newSubscribers, true); Console.WriteLine(results.TotalNewSubscribers + " subscribers added"); Console.WriteLine(results.TotalExistingSubscribers + " total subscribers in list"); } catch (CreatesendException ex) { ErrorResult<BulkImportResults> error = (ErrorResult<BulkImportResults>)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); if (error.ResultData != null) { //handle the returned data BulkImportResults results = error.ResultData; //success details are here as normal Console.WriteLine(results.TotalNewSubscribers + " subscribers were still added"); //but we also have additional failure detail foreach (ImportResult result in results.FailureDetails) { Console.WriteLine("Failed Address"); Console.WriteLine(result.Message + " - " + result.EmailAddress); } } } catch (Exception ex) { // Handle some other failure Console.WriteLine(ex.ToString()); } }
public string Add(string emailAddress, string name, List<SubscriberCustomField> customFields, bool resubscribe, bool restartSubscriptionBasedAutoresponders) { return HttpHelper.Post<Dictionary<string, object>, string>( AuthCredentials, string.Format("/subscribers/{0}.json", ListID), null, new Dictionary<string, object>() { { "EmailAddress", emailAddress }, { "Name", name }, { "CustomFields", customFields }, { "Resubscribe", resubscribe }, { "RestartSubscriptionBasedAutoresponders", restartSubscriptionBasedAutoresponders } }); }
private static string[] GetPairs(NameValueCollection nvc) { List<string> keyValuePair = new List<string>(); foreach (string key in nvc.AllKeys) { string encodedKey = HttpUtility.UrlEncode(key) + "="; foreach (string value in nvc.GetValues(key)) keyValuePair.Add(encodedKey + HttpUtility.UrlEncode(value)); } return keyValuePair.ToArray(); }
public static string Create(string clientID, string subject, string name, string fromName, string fromEmail, string replyTo, string htmlUrl, string textUrl, List<string> listIDs, List<string> segmentIDs) { return HttpHelper.Post<Dictionary<string, object>, string>( string.Format("/campaigns/{0}.json", clientID), null, new Dictionary<string, object>() { { "Subject", subject }, { "Name", name }, { "FromName", fromName}, { "FromEmail", fromEmail }, { "ReplyTo", replyTo }, { "HtmlUrl", htmlUrl }, { "TextUrl", textUrl }, { "ListIDs", listIDs }, { "SegmentIDs", segmentIDs } }); }
public static string CreateFromTemplate(AuthenticationDetails auth, string clientID, string subject, string name, string fromName, string fromEmail, string replyTo, List<string> listIDs, List<string> segmentIDs, string templateID, TemplateContent templateContent) { return HttpHelper.Post<Dictionary<string, object>, string>( auth, string.Format("/campaigns/{0}/fromtemplate.json", clientID), null, new Dictionary<string, object>() { { "Subject", subject }, { "Name", name }, { "FromName", fromName}, { "FromEmail", fromEmail }, { "ReplyTo", replyTo }, { "ListIDs", listIDs }, { "SegmentIDs", segmentIDs }, { "TemplateID", templateID }, { "TemplateContent", templateContent } }); }
void CreateCustomField() { List list = new List(listID); try { string newCustomFieldKey = list.CreateCustomField("NewCustomField", CustomFieldDataType.Text, null); Console.WriteLine(newCustomFieldKey); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { //handle some other failure } }
void CreateMultiOptionCustomField() { List list = new List(listID); try { List<string> options = new List<string>() { "Option 1", "Option 2", "Option 3" }; string newCustomFieldKey = list.CreateCustomField("NewCustomField", CustomFieldDataType.MultiSelectOne, options); Console.WriteLine(newCustomFieldKey); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { //handle some other failure } }
public BulkImportResults Import(List<SubscriberDetail> subscribers, bool resubscribe) { List<object> reworkedSusbcribers = new List<object>(); foreach (SubscriberDetail subscriber in subscribers) { Dictionary<string, object> subscriberWithoutDate = new Dictionary<string, object>() { { "EmailAddress", subscriber.EmailAddress }, { "Name", subscriber.Name }, { "CustomFields", subscriber.CustomFields } }; reworkedSusbcribers.Add(subscriberWithoutDate); } return HttpHelper.Post<Dictionary<string, object>, BulkImportResults, ErrorResult<BulkImportResults>>( string.Format("/subscribers/{0}/import.json", ListID), null, new Dictionary<string, object>() { { "Subscribers", reworkedSusbcribers }, { "Resubscribe", resubscribe } }); }
public void GetActiveSubscribers() { List list = new List(auth, ListID); try { List<SubscriberDetail> allSubscribers = new List<SubscriberDetail>(); //get the first page, with an old date to signify entire list PagedCollection<SubscriberDetail> firstPage = list.Active(new DateTime(1900, 1, 1), 1, 50, "Email", "ASC"); allSubscribers.AddRange(firstPage.Results); if(firstPage.NumberOfPages > 1) for (int pageNumber = 2; pageNumber <= firstPage.NumberOfPages; pageNumber++) { PagedCollection<SubscriberDetail> subsequentPage = list.Active(new DateTime(1900, 1, 1), pageNumber, 50, "Email", "ASC"); allSubscribers.AddRange(subsequentPage.Results); } foreach(SubscriberDetail subscriberDetail in allSubscribers) Console.WriteLine(string.Format( "Subscriber with email address {0} reads mail with {1}.", subscriberDetail.EmailAddress, subscriberDetail.ReadsEmailWith)); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { // Handle some other failure Console.WriteLine(ex.ToString()); } }
public void SendPreview(List<string> recipients, string personalize) { HttpHelper.Post<Dictionary<string, object>, string>( AuthCredentials, string.Format("/campaigns/{0}/sendpreview.json", CampaignID), null, new Dictionary<string, object>() { { "PreviewRecipients", recipients}, { "Personalize", personalize} }); }
public static string CreateFromTemplate(string clientID, string subject, string name, string fromName, string fromEmail, string replyTo, List<string> listIDs, List<string> segmentIDs, string templateID, TemplateContent templateContent) { return CreateFromTemplate(CreateSendOptions.ApiKey, clientID, subject, name, fromName, fromEmail, replyTo, listIDs, segmentIDs, templateID, templateContent); }
/// <summary> /// Creates a campaign using the campaign details provided. /// </summary> /// <param name="clientID">Client ID of the client for whom the /// campaign should be created</param> /// <param name="subject">A subject for the campaign</param> /// <param name="name">A name for the campaign</param> /// <param name="fromName">From name for the campaign</param> /// <param name="fromEmail">From email address for the campaign</param> /// <param name="replyTo">Reply-to address for the campaign</param> /// <param name="htmlUrl">URL for the HTML content for the /// campaign</param> /// <param name="textUrl">URL for the text content for the campaign. /// Note that you may provide textUrl as null or an empty string and /// the text content for the campaign will be generated from the HTML /// content.</param> /// <param name="listIDs">IDs of the lists to which the campaign /// will be sent</param> /// <param name="segmentIDs">IDs of the segments to which the /// campaign will be sent</param> /// <returns>The ID of the newly created campaign</returns> public static string Create(string clientID, string subject, string name, string fromName, string fromEmail, string replyTo, string htmlUrl, string textUrl, List<string> listIDs, List<string> segmentIDs) { return Create(CreateSendOptions.ApiKey, clientID, subject, name, fromName, fromEmail, replyTo, htmlUrl, textUrl, listIDs, segmentIDs); }
public void SendPreview(List<string> recipients, string personalize) { string json = HttpHelper.Post(string.Format("/campaigns/{0}/sendpreview.json", _campaignID), null, JavaScriptConvert.SerializeObject( new Dictionary<string, object>() { { "PreviewRecipients", recipients}, { "Personalize", personalize} }) ); }
/// <summary> /// Updates the subscriber with current email address of "*****@*****.**" to have the new email /// "*****@*****.**", while leaving the name unchanged. /// </summary> void UpdateWithNewEmailAndUnchangedNameDontResubscribe() { Subscriber subscriber = new Subscriber(listID); try { List<SubscriberCustomField> customFields = new List<SubscriberCustomField>(); customFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey", Value = "Value" }); customFields.Add(new SubscriberCustomField() { Key = "CustomFieldKey2", Value = "Value2" }); subscriber.Update("*****@*****.**", "*****@*****.**", null, customFields, false); Console.WriteLine("Subscriber Updated successfully with new email: [email protected]. Name was unchanged"); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { //handle some other failure } }
public void Update(string emailAddress, string newEmailAddress, string name, List<SubscriberCustomField> customFields, bool resubscribe) { NameValueCollection queryArguments = new NameValueCollection(); queryArguments.Add("email", emailAddress); HttpHelper.Put<Dictionary<string, object>, string>( string.Format("/subscribers/{0}.json", ListID), queryArguments, new Dictionary<string, object>() { { "EmailAddress", newEmailAddress }, { "Name", name }, { "CustomFields", customFields }, { "Resubscribe", resubscribe } }); }
public BulkImportResults Import(List<SubscriberDetail> subscribers, bool resubscribe) { return Import(subscribers, resubscribe, false); }