You manage a particular contact's subscription to contact lists by modifying the contact's detail data. The contact list subscriptions are described in <ContactLists> element of a contact's details. Each contact list to which the contact has subscribed is described in <ContactList> element inside <ContactLists>. You add a contact to a contact list by adding another <ContactList> element for the contact list to which you are adding the contact. You remove a contact from a contact list by removing the corresponding <ContactList> element for the contact list from <ContactLists> group node.
NOTE: The various elements in the Contact XML used to create and update contacts are subject to field length limitations. Please see the Contacts Collection and Resource reference for details. XML that violates these field length constraints will be rejected.
After manipulating the XML to contain only the contact lists in which you want to keep the contact, you need to issue the PUT method against the contact resource:
https://api.constantcontact.com/ws/customers/{username}/contacts/{contact-id}
See below an example of the XML required to associate existing contact u86597@example.com
with contact lists 1, 11, 12 and 14 in the joesflowers
account. Note that after the PUT, contact u86597@example.com
will be on ONLY contact lists 1, 11, 12 and 14 and will be removed from any other lists the contact was on previously. in other words, you want to include contact lists on which you want to leave the contact after the update.
<entry xmlns="http://www.w3.org/2005/Atom">
<id>http://api.constantcontact.com/ws/customers/joesflowers/contacts/101</id>
<title type="text">Contact: u86597@example.com</title>
<updated>2008-04-25T19:29:06.096Z</updated>
<author> </author>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/joesflowers/contacts/101">
<EmailAddress>u86597@example.com</EmailAddress>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/1"></ContactList>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/11"></ContactList>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/12"></ContactList>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/14"></ContactList>
</ContactLists>
</Contact>
</content>
</entry>
Note that <OptInSource> element is required, and must be ACTION_BY_CUSTOMER for any contact list that was not included in a sign up form. In other words, if the user is subscribing to a list, you can use ACTION_BY_CONTACT, but if the account owner is adding a user on his or her behalf through this API, then you must use ACTION_BY_CUSTOMER.
Setting the Opt In Source to ACTION_BY_CONTACT will trigger any applicable emails to go out to the contact, such as welcome emails or change of interest emails. Setting the Opt In Source to ACTION_BY_CUSTOMER will suppress those emails, but will still trigger Autoresponder emails, if applicable (please note that autoresponder emails are only triggered for contacts that are not on any existing lists at the time that they are added to a list that is set to receive autoresponders).