I'm attempting to empty a list of all contacts in it, and if the contact itself is in no more lists, remove it from Constant Contact. The below code ism't working as the list is completely unaffected. What am I doing wrong? Is there a better way?
public void ClearContactList(ConstantContactFactory constantContactFactory, ContactList contactList)
var contactService = constantContactFactory.CreateContactService();
var listService = constantContactFactory.CreateListService();
var contacts = listService.GetContactsFromList(contactList.Id, null);
foreach (var item in contacts.Results)//For each contact in the selected list
contactService.DeleteContactFromList(item.Id, contactList.Id);//Delete the contact from the current list
if (item.Lists.Count < 1) //If the contact is in no other lists we delete it completely
Solved! Go to Solution.
Keep in mind when working with contacts and their lists. You are not actually working with the lists themselves you are working with the contact and if it has any listIDs that it belongs to. The only way to remove every contact from a specific list is with using one of our Bulk Method endpoints.
Using the above endpoint you can specify multiple listIDs and each one submitted will be cleared of all contacts. However; after that you would then have to do a GET on the contact itself to see if that specific contact is still a member of any other lists.
This above endpoint will remove specific email addresses from specific lists instead of removing all contacts from a list. However; afterwards you would still have to do a GET on the contact to see if it is still a member of another list.
Now either of these options will put the contact in the "REMOVED" state if they end up removing the last list from a contact, but also please note this is different from "UNSUBSCRIBED".
That was only somewhat helpful. I'm using the C# wrapper provided and the CTCT.dll in C#. How do I call the endpoint in that context? Is there some service I have to invoke?
Both of those endpoints have been coded in to our C# wrapper.