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.

C# SDK -- Remove contact from specific list

Highlighted
Occasional Participant

C# SDK -- Remove contact from specific list

I am trying to remove a single contact from a specific list.  I am using the C# SDK but do not see a method that will allow me to do this.   

 

Any help would be appreciated.

 

13 REPLIES 13
Highlighted
Occasional Participant

Re: C# SDK -- Remove contact from specific list

I have scoured the support forum and google.  I think that this functionality is made a little more complicated that it needs to be (since many people ask for it and expect this normal functionality to be a part of the SDK), but maybe I am missing something.

In the following code, I want to add to the NewList and remove from the NoActList.

 

    private void AddToNew(Contact contact, List<ContactList> contactLists)
    {
        List<string> email = new List<string>();
        email.Add(txtEmail.Text.ToLower());
        ContactOptInList NewList = new ContactOptInList();
        NewList.ContactList = new ConstantContactBO.ContactList("5");

        ContactOptInList NoActList = new ContactOptInList();
        NoActList.ContactList = new ConstantContactBO.ContactList("6");

        string _nextChunkId;
        IList<Contact> lstContact = Utility.SearchContactByEmail(authdata, email, out _nextChunkId);

        //if they are already in a list
        if (lstContact.Count > 0)
        {
            Contact c = Utility.GetContactDetailsById(authdata, lstContact[0].Id);
            c.OptInSource = ContactOptSource.ActionByCustomer;
            c.ContactLists.Add(NewList);
            c.ContactLists.Remove(NoActList);

            try
            {
                Utility.UpdateContactFullForm(authdata, c);
            }
            catch (Exception ex)
            {
            }
        }

 

 

Why doesn't this work?


Highlighted
Employee

Re: C# SDK -- Remove contact from specific list

Chad,

 

To update a contact it would be best to do a GET on the contact that way the XML you get is well formed.  You update the nodes you want to change.  In this case, you would be changing the ContactLists node reflect what lists this contact would be on and then complete a PUT to update the contact.

 

If this is not working for you, please reply with the error code and response you are receiving as well as the XML you are sending to us.

 

WIth this, we should be able to look into why this is not working properly for you.

 

Thanks, 

 

 

Andrew Weber
Associate Product Manager for EventSpot
Highlighted
Occasional Participant

Re: C# SDK -- Remove contact from specific list

Can you provide a link to constant contact documentation performing the method you are suggesting?

Highlighted
Employee

Re: C# SDK -- Remove contact from specific list

Chad,

 

The code below will search for all contacts with a specific email and remove it from all lists but list 22.

 

            string _nextChunk;

            List<string> myEmail = new List<string>();

            myEmail.Add("aweber@constantcontact.com");
            IList<Contact> myList = Utility.SearchContactByEmail(authdata, myEmail, out _nextChunk);

            ContactOptInList newList = new ContactOptInList();
            newList.ContactList = new ConstantContactBO.ContactList("22");

            foreach (Contact contact in myList)
            {
                contact.ContactLists.Add(newList);
                Utility.UpdateContactFullForm(authdata, contact);
            }

 

Andrew Weber
Associate Product Manager for EventSpot
Highlighted
Occasional Participant

Re: C# SDK -- Remove contact from specific list

Thanks.  

 

So what you are telling me is that there is no way to actually remove someone from a specific email list without getting all of the lists they are subscribed to, "adding" those sans the one list you don't want them in, and resubmitting them?  

 

Seriously?

Highlighted
Employee

Re: C# SDK -- Remove contact from specific list

Hey Chad,

 

You are correct.  Our API takes the submitted XML for Lists and completely wipes out the old data for the new data.

Andrew Weber
Associate Product Manager for EventSpot
Highlighted
Occasional Visitor

Re: C# SDK -- Remove contact from specific list

Hi Andrew,

 

"Our API takes the submitted XML for Lists and completely wipes out the old data for the new data."

 

This behavior isn't what I just experienced. I am trying to move a contact from a list to another and I am doing so by sending a PUT request with the list node only containing one list (the list to move the contact to).

 

What I experienced is that the API returns a contact assigned to no list (list node empty), while the website shows the contact in both list (the old and the new one).

 

Could you help?

 

Regards,

Richard

Highlighted
Honored Contributor

Re: C# SDK -- Remove contact from specific list

Hello Richard,

 

It is the intended behavior that a contact should change to match the data that is sent by the application and what you are seeing is not the intended or normal behavior. In ordre to look into what is happening, we will need details on the contact that you are working on, as well as the account that you are working with.

 

If it is possible, it would be best to email us at webservices@constantcontact.com with the following info:

 

- Username for the Constant Contact account where you are having issues

- Email address of the contact that is being worked on

- If possible, the contact ID of the contact that is being worked on

 

Best Regards,

 

Elijah G.
API Support Engineer
Highlighted
Occasional Participant

Re: C# SDK -- Remove contact from specific list

Contact c = Utility.GetContactDetailsById(authdata, ContactID);

ContactOptInList newList = new ContactOptInList();

 

newList.ContactList = new ConstantContactBO.ContactList("33");
c.ContactLists.Add(newList);

 

c.OptInSource = ContactOptSource.ActionByCustomer;
Utility.UpdateContactFullForm(authdata, c);

 

So based on what you've posted in this thread this contact with a contactid of ContactID should only be on list 33?

Because when I execute this code they are still in a group they were previously assigned to.

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