We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Developing a System to Add users to a Mailing List

Occasional Participant

Developing a System to Add users to a Mailing List

 I am creating a function that will add a user to a specific Mailing list.  Currently I am doing this by using a post (Creating a new contact), and adding the new contact to the targeted list_id.

However, what I have noticed is that if a user is deleted from the mailing list, the user still exists, but is under 'Removed' meaning that it is not under any list.  When this happens, I cannot use my current method of adding the user, cause I get a 409 error.

My question is this, when it is 409, is that specific to a user already being created?  if it is.. is it sufficient to simply use a PUT to add the user to the list instead of a POST.

My second question is when I use a POST, how do I obtain the contact-id required to do the PUT?  I am only given an email address to add to the list  for this function.  Is there a way to grab the contact-id of the email address?

Thank you so much for any help!  Much appreciated

Wesley Yang


Hello Wesley,

If a contact is not on the current list, or is on the Removed list, this contact is still considered an existing contact, so it will return the 409 Error. A great way to go around this is to first do a search for the contact using the search by email address feature that we have. If the contact exists, do a PUT call to the Contact Collection API, other do a POST call.

To answer your second question, when doing the search feature, it will return XML that has the Contact ID information, so you will be able to use that when you do your PUT call.

If you have any further questions please let me know.


Benjamin Soder
NOC Analyst
Constant Contact
Occasional Participant

Thank you so much Ben, I was just reading about that Search Feature!  If I come across any other problems I will not hesitate to ask.





Occasional Participant

EDIT: Fixed!  I replaced 'http://' with 'https://' for the CURLOPT_URL setting.  


Hey Ben, everything is working right now except for the PUT statement.  I keep seem to be getting a 403 Forbidden error.  The curl settings I have are these:


curl_setopt($ch, CURLOPT_URL, $puturl); // the value of the ID element from the search 


curl_setopt($ch, CURLOPT_USERPWD, $authstr); // the key%user:pass string

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

curl_setopt($ch, CURLOPT_POSTFIELDS, $post->asXML()); //the $post is the XML that I have built

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/atom+xml"));

curl_setopt($ch, CURLOPT_HEADER, false); // Do not return headers

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // If you set this to 0, it will take you to a page with the http response


The XML I am building for the Put is this:



$post = new SimpleXMLElement('<entry></entry>');

$post->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');

$post->addChild('id', $id);

$title = $post->addChild('title', "Contact: ".$emailAddr); 

$title->addAttribute('type', 'text');

$post->addChild('updated', date('c'));

$post->addChild('author', "");

$content = $post->addChild('content');

$content->addAttribute('type', 'application/vnd.ctct+xml');

$contact = $content->addChild('Contact');

$contact->addAttribute('xmlns', 'http://ws.constantcontact.com/ns/1.0/');

$contact->addAttribute('id', $id);

$contact->addChild('EmailAddress', $emailAddr);

$contact->addChild('OptInSource', 'ACTION_BY_CUSTOMER');

$contactlists = $contact->addChild('ContactLists');

// loop through each of the defined contact lists

foreach($contactListId AS $listId) {    

    $contactlist = $contactlists->addChild('ContactList');

    $contactlist->addAttribute('id', 'http://api.constantcontact.com/ws/customers/' . $ccuser . '/lists/' . $listId);




Developer Portal

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

Visit Page