cancel
Showing results for 
Search instead for 
Did you mean: 

Clearing a Constant Contact list

SOLVED
Occasional Contributor

Clearing a Constant Contact list

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
                        contactService.DeleteContact(item);
         }
}

3 REPLIES 3
Moderator

Re: Clearing a Constant Contact list

Hello @DavidL7089,

 

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.

 

http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-clear-contactlists.htm...

 

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.

 

http://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-remove-contacts-api.ht...

 

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".


Regards,
Jimmy D.
Tier II API Support Engineer
Occasional Contributor

Re: Clearing a Constant Contact list

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? 

Highlighted
Moderator

Re: Clearing a Constant Contact list