The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Clearing a Constant Contact list

SOLVED
Go to solution
Highlighted
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);
         }
}

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Clearing a Constant Contact list

3 REPLIES 3
Highlighted
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
Highlighted
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

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured