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.

Problem Adding New Contact to List


Problem Adding New Contact to List

 Hi All,

We are having a problem adding a new contact to one of our lists using the API. We are attempting to add the contact using PHP. The return value indicates that the addition of the new contact has been successful, however when we check our lists, the new contact does not show in our contact list. The PHP code that we are using is as follows:



$ccuser = 'xxx';

$ccpass = 'xxx';

$cckey  = 'xxx';

// these values are POSTED from the previous page

$firstName  = htmlspecialchars(trim($_REQUEST));

$lastName   = htmlspecialchars(trim($_REQUEST));  

$emailAddr  = htmlspecialchars(trim($_REQUEST));

$phone = htmlspecialchars(trim($_REQUEST));

$zip        = htmlspecialchars(trim($_REQUEST));


// represents the contact list identification number(s)

$contactListId = 1;

$contactListId = (!is_array($contactListId)) ? array($contactListId) : $contactListId;


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

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


$title = $post->addChild('title', "");

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


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

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

$post->addChild('id', 'data:,none');


$summary = $post->addChild('summary', 'Contact');

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


$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->addChild('EmailAddress', $emailAddr);

$contact->addChild('FirstName', $firstName);

$contact->addChild('LastName', $lastName);

$contact->addChild('HomePhone', $phone);

$contact->addChild('PostalCode', $zip);

$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);



$posturl = "https://api.constantcontact.com/ws/customers/{$ccuser}/contacts";

$authstr = $cckey . '%' . $ccuser . ':' . $ccpass;


$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, $posturl);


curl_setopt($ch, CURLOPT_USERPWD, $authstr);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $post->asXML());

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


$response = curl_exec($ch);




// returns true on success, false on error: We are receiving a "1"




Any help resolving this issue is greatly appreciated.


I needed to make a few slight modifications to your code, since I do not have the actual form that submits to this page. After manually putting in a few test values, I was able to successfuly get your PHP code to work and create a new contact by adding the following line to your curl option:


curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


This should allow you to successfully create your contact using your PHP code above. I hope this helps, please let me know if this does not resolve your issue.

David J

Developer Portal

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

Visit Page