// ------------------------------------------------------------ // Name: PrepareListForCSV // Abstract: Prepare a list to be used to create a CSV // ------------------------------------------------------------ public static Dictionary<string, string> PrepareListForCSV(String strListID) { Dictionary<string, string> dctListSubscribers = new Dictionary<string, string>(); try { String strStatus = ""; // Newsletter Publication List // Get subscriber dates ET_List_Subscriber getListSub = new ET_List_Subscriber(); getListSub.AuthStub = m_etcTDClient; getListSub.Props = new string[] { "SubscriberKey", "Status" }; getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { strListID } }; GetReturn getLSResponse = getListSub.Get(); Console.WriteLine("Get Status: " + getLSResponse.Status.ToString()); Console.WriteLine("Message: " + getLSResponse.Message.ToString()); Console.WriteLine("Code: " + getLSResponse.Code.ToString()); Console.WriteLine("Results Length: " + getLSResponse.Results.Length); int intResults = getLSResponse.Results.Length; // CREATE HEADERS: "Subscriber Key" & "Status" // Get all subscriber keys associated with active subscribers while (getLSResponse.MoreResults == true || intResults > 0) { foreach (ET_List_Subscriber sub in getLSResponse.Results) { strStatus = sub.Status.ToString(); dctListSubscribers.Add(sub.SubscriberKey, strStatus); Console.WriteLine("Added Subscriber: " + sub.SubscriberKey + " Status: " + strStatus); } getLSResponse = getListSub.GetMoreResults(); intResults = getLSResponse.Results.Length; } Console.WriteLine("Retrieved List Subscriber Statuses from ListID: " + strListID); } catch (Exception excError) { // Display Error Console.WriteLine("Error: " + excError.ToString()); } return dctListSubscribers; }
// ------------------------------------------------------------ // Name: UpdateConvertedProspects // Abstract: Retrieve subscribers from a list // ------------------------------------------------------------ public static void SetPublicationListBooleans() { Dictionary<string, string> dctNewsletterListSubscribers = new Dictionary<string, string>(); Dictionary<string, string> dctDENewsletterSubscribers = new Dictionary<string, string>(); Dictionary<string, string> dctRemindersListSubscribers = new Dictionary<string, string>(); Dictionary<string, string> dctDERemindersSubscribers = new Dictionary<string, string>(); List<string> alstrValidSubscriberKeys = new List<string>(); try { string strSubscriberKey = ""; string strStatus = ""; string strDEStatus = ""; int intUpdateRecordCount = 0; int intResults = 0; string x; // Data DateTime dtmCreatedDate = DateTime.Now; // Newsletter Publication List // Get subscriber dates ET_List_Subscriber getListSub = new ET_List_Subscriber(); getListSub.AuthStub = m_etcTDClient; getListSub.Props = new string[] { "SubscriberKey", "Status", "CreatedDate" }; getListSub.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { "2726" } }; GetReturn getLSResponse = getListSub.Get(); Console.WriteLine("Get Status: " + getLSResponse.Status.ToString()); Console.WriteLine("Message: " + getLSResponse.Message.ToString()); Console.WriteLine("Code: " + getLSResponse.Code.ToString()); Console.WriteLine("Results Length: " + getLSResponse.Results.Length); intResults = getLSResponse.Results.Length; // Get all subscriber keys associated with active subscribers while (getLSResponse.MoreResults == true || intResults > 0) { foreach (ET_List_Subscriber sub in getLSResponse.Results) { strStatus = sub.Status.ToString(); dctNewsletterListSubscribers.Add(sub.SubscriberKey, strStatus); Console.WriteLine("Added Subscriber: " + sub.SubscriberKey + " Status: " + strStatus); } getLSResponse = getListSub.GetMoreResults(); intResults = getLSResponse.Results.Length; } Console.WriteLine("Retrieved Newsletter List Subscription Status"); // Get all customers and their 'NewsletterPublicationList' field from CustomerBaseDatabase Console.WriteLine("\n Retrieve All Rows from DataExtension"); ET_DataExtensionRow deRowGetNewsletter = new ET_DataExtensionRow(); deRowGetNewsletter.AuthStub = m_etcTDClientShared; deRowGetNewsletter.DataExtensionName = "CustomerDatabase"; deRowGetNewsletter.Props = new string[] { "SubscriberKey", "NewsletterPublicationList" }; GetReturn grRowNewsletter = deRowGetNewsletter.Get(); Console.WriteLine("Get Status: " + grRowNewsletter.Status.ToString()); Console.WriteLine("Message: " + grRowNewsletter.Message.ToString()); Console.WriteLine("Code: " + grRowNewsletter.Code.ToString()); Console.WriteLine("Results Length: " + grRowNewsletter.Results.Length); intResults = grRowNewsletter.Results.Length; while (grRowNewsletter.MoreResults == true || intResults > 0) { foreach (ET_DataExtensionRow column in grRowNewsletter.Results) { strSubscriberKey = column.ColumnValues["SubscriberKey"]; strStatus = column.ColumnValues["NewsletterPublicationList"]; if (dctNewsletterListSubscribers.TryGetValue(strSubscriberKey, out x) == true) { dctDENewsletterSubscribers.Add(strSubscriberKey, strStatus); Console.WriteLine("Added NPL customer: " + strSubscriberKey); } } grRowNewsletter = deRowGetNewsletter.GetMoreResults(); intResults = grRowNewsletter.Results.Length; } // Update statuses ET_DataExtensionRow deRowPatchNewsletter = null; foreach (KeyValuePair<string, string> entry in dctDENewsletterSubscribers) { strSubscriberKey = entry.Key; strDEStatus = entry.Value; // if our status = active, set to true strStatus = dctNewsletterListSubscribers[strSubscriberKey]; if (strStatus.Equals("Active") == true) { strStatus = "True"; } else { strStatus = "False"; } // Is the status of our subscriber the same on the All Subscribers list as it is on the Data Extension? if (strDEStatus.Equals(strStatus) == false) { intUpdateRecordCount += 1; // No, update the verified email field deRowPatchNewsletter = new ET_DataExtensionRow(); deRowPatchNewsletter.AuthStub = m_etcTDClientShared; deRowPatchNewsletter.DataExtensionCustomerKey = "CustomerDBKey"; deRowPatchNewsletter.ColumnValues.Add("SubscriberKey", strSubscriberKey); deRowPatchNewsletter.ColumnValues.Add("NewsletterPublicationList", strStatus); PatchReturn patchRowResponse = deRowPatchNewsletter.Patch(); Console.WriteLine("Post Status: " + patchRowResponse.Status.ToString()); Console.WriteLine("Count: " + intUpdateRecordCount.ToString()); Console.WriteLine("Changed newsletter boolean for subscriber: " + strSubscriberKey + " from " + strDEStatus + " to " + strStatus); } } Console.WriteLine("Completed Newsletter Boolean Update"); // Reminders Publication List // Get subscriber dates ET_List_Subscriber getListSubReminders = new ET_List_Subscriber(); getListSubReminders.AuthStub = m_etcTDClient; getListSubReminders.Props = new string[] { "SubscriberKey", "Status", "CreatedDate" }; getListSubReminders.SearchFilter = new SimpleFilterPart() { Property = "ListID", SimpleOperator = SimpleOperators.equals, Value = new string[] { "2727" } }; GetReturn getLSResponseReminders = getListSubReminders.Get(); Console.WriteLine("Get Status: " + getLSResponseReminders.Status.ToString()); Console.WriteLine("Message: " + getLSResponseReminders.Message.ToString()); Console.WriteLine("Code: " + getLSResponseReminders.Code.ToString()); Console.WriteLine("Results Length: " + getLSResponseReminders.Results.Length); intResults = getLSResponseReminders.Results.Length; // Get all subscriber keys associated with active subscribers while (getLSResponseReminders.MoreResults == true || intResults > 0) { foreach (ET_List_Subscriber sub in getLSResponseReminders.Results) { strStatus = sub.Status.ToString(); dctRemindersListSubscribers.Add(sub.SubscriberKey, strStatus); Console.WriteLine("Added Subscriber: " + sub.SubscriberKey + " Status: " + strStatus); } getLSResponseReminders = getListSubReminders.GetMoreResults(); intResults = getLSResponseReminders.Results.Length; } Console.WriteLine("Retrieved Reminders List Subscription Status"); // Get all customers and their 'ReminderssPublicationList' field from CustomerBaseDatabase Console.WriteLine("\n Retrieve All Rows from DataExtension"); ET_DataExtensionRow deRowGetReminders = new ET_DataExtensionRow(); deRowGetReminders.AuthStub = m_etcTDClientShared; deRowGetReminders.DataExtensionName = "CustomerDatabase"; deRowGetReminders.Props = new string[] { "SubscriberKey", "RemindersPublicationList" }; GetReturn grRowReminders = deRowGetReminders.Get(); Console.WriteLine("Get Status: " + grRowReminders.Status.ToString()); Console.WriteLine("Message: " + grRowReminders.Message.ToString()); Console.WriteLine("Code: " + grRowReminders.Code.ToString()); Console.WriteLine("Results Length: " + grRowReminders.Results.Length); intResults = grRowReminders.Results.Length; while (grRowReminders.MoreResults == true || intResults > 0) { foreach (ET_DataExtensionRow column in grRowReminders.Results) { strSubscriberKey = column.ColumnValues["SubscriberKey"]; strStatus = column.ColumnValues["RemindersPublicationList"]; if (dctRemindersListSubscribers.TryGetValue(strSubscriberKey, out x) == true) { dctDERemindersSubscribers.Add(strSubscriberKey, strStatus); Console.WriteLine("Added RPL customer: " + strSubscriberKey); } } grRowReminders = deRowGetReminders.GetMoreResults(); intResults = grRowReminders.Results.Length; } intUpdateRecordCount = 0; // Update statuses ET_DataExtensionRow deRowPatchReminders = null; foreach (KeyValuePair<string, string> entry in dctDERemindersSubscribers) { strSubscriberKey = entry.Key; strDEStatus = entry.Value; // if our status = active, set to true strStatus = dctRemindersListSubscribers[strSubscriberKey]; if (strStatus.Equals("Active") == true) { strStatus = "True"; } else { strStatus = "False"; } // Is the status of our subscriber the same on the All Subscribers list as it is on the Data Extension? if (strDEStatus.Equals(strStatus) == false) { intUpdateRecordCount += 1; // No, update the verified email field deRowPatchReminders = new ET_DataExtensionRow(); deRowPatchReminders.AuthStub = m_etcTDClientShared; deRowPatchReminders.DataExtensionCustomerKey = "CustomerDBKey"; deRowPatchReminders.ColumnValues.Add("SubscriberKey", strSubscriberKey); deRowPatchReminders.ColumnValues.Add("RemindersPublicationList", strStatus); PatchReturn patchRowResponse = deRowPatchReminders.Patch(); Console.WriteLine("Post Status: " + patchRowResponse.Status.ToString()); Console.WriteLine("Count: " + intUpdateRecordCount.ToString()); Console.WriteLine("Changed reminders boolean for subscriber: " + strSubscriberKey + " from " + strDEStatus + " to " + strStatus); } } Console.WriteLine("Completed Reminders Boolean Update"); } catch (Exception excError) { // Display Error Console.WriteLine("Error: " + excError.ToString()); } }