cancel
Showing results for 
Search instead for 
Did you mean: 

C# SDK -- Remove contact from specific list

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
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?


CTCT 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
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?

CTCT 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
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?

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

Occasional Participant

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

Julie,

 

I use the following code, and it works about 3/4 of the time.  It's frustrating.  BTW listnum param is the numerical id of your lists.  

 private void AddToList(string listNum)
    {

        List<string> email = new List<string>();
        email.Add(txtEmail.Text.ToLower());

        ContactOptInList theList = new ContactOptInList();
        theList.ContactList = new ConstantContactBO.ContactList(listNum);
        theList.OptInSource = ContactOptSource.ActionByCustomer;

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

        //if they are already in a list
        if (lstContact.Count > 0)
        {
            string _nextChunk;

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

            myEmail.Add(txtEmail.Text.ToLower());
            IList<Contact> myList = Utility.SearchContactByEmail(authdata, myEmail, out _nextChunk);

            foreach (Contact c in myList)
            {
                c.ContactLists.Add(theList);

                try
                {
                    Utility.UpdateContactFullForm(authdata, c);
                }
                catch (Exception ex)
                {
                }
            }
        }
        else
        {
            Contact c = new Contact();
            c.EmailAddress = txtEmail.Text.ToLower();
            c.OptInSource = ContactOptSource.ActionByCustomer;
            c.ContactLists.Add(theList);

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



    }

 

 

Moderator

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

Feel free to give our API support a shout if you're still having issues with this, and we can jump in and take a look.

Nick Galbraith
Support Engineer