Update in Constant contact

Regular Participant

Update in Constant contact

I'm trying to update a contact information, I want to update all the fields including email.


1) Tried the PUT functionality and 204 is getting but the fileds are not updating

and it is inserting into the list as a new entry.




            Follwing is the sample code used





$UN = "username";

$PW = "password";

$Key = "key-key-key-key-key";

$SubID ="3" ;//REPLACE WITH A VALID CONTACT Id, Which you can retrieve with a GET

 $entry = '<entry xmlns="http://www.w3.org/2005/Atom">


  <title type="text">Contact: harihariha@3examghfghplexcvxc.com</title>



  <content type="application/vnd.ctct+xml">

  <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'">


      <FirstName>' . $first_name . '</FirstName>




        <ContactList id="http://api.constantcontact.com/ws/customers/'.$UN.'/lists/4">







    The XML above will change the First name and Last name to  Joe6 Smith6 Need to make

    sure you have listed all the lists the contact belongs to, in addition to any lists you would like

    the Contact added to.  If you leave a Contact List out, the Contact will be removed from that

    Contact List.  This is format of Contact List XML entries:


            <ContactList id="http://api.constantcontact.com/ws/customers/'.$UN.'/lists/7">


            <ContactList id="http://api.constantcontact.com/ws/customers/'.$UN.'/lists/55">


            <ContactList id="http://api.constantcontact.com/ws/customers/'.$UN.'/lists/57">




// create a temp file and load the xml in to it.

$tmpfile = tmpfile();

fwrite($tmpfile, $entry);

fseek($tmpfile, 0);

// Initialize the curl session

$request ="http://api.constantcontact.com/ws/customers/".$UN."/contacts/".$SubID;

$session = curl_init($request);

// Set up Digest authentication. Put your API key, and CTCT username/pwd here

$userNamePassword = $Key . '%' . $UN . ':' . $PW ;


curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);

curl_setopt($session, CURLOPT_INFILE, $tmpfile);

fclose($tmpfile); // Close temp file because it no longer needed

curl_setopt($session, CURLOPT_PUT, 1);

curl_setopt($session, CURLOPT_INFILESIZE, strlen($entry));

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

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

curl_setopt($session, CURLOPT_RETURNTRANSFER, 0);

$response = curl_exec($session);

$httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);



if ($httpcode > 199 && $httpcode < 300)


echo  "It works!!" ; // You might want GET the updated Contact and display it



   { echo "<br> There a Problem <br>Error Code: ". $httpcode ; }






Could u please help me to figure out this issue




Hello Aravind,

After testing the sample put code in the RESTClient I was not able to replicate the issue that you are having. You should be able to PUT to a specific contact and update all information including the Email Address provided that the email address is not in use by another contact. The PUT command should not create a new record. You want to make sure that the contact ID you are PUTting to is correct if you are using GET variables to set it. Also, I recommend testing your XML statement using the RESTClient prior to implementing it into a PHP script.

Dan H

Support Engineer, Constant Contact

Occasional Participant

@aravindpilla per @moonwell on 2 Feb 2009 there is a bug using the API when updating a contact when specifying lists they are already subscribed to. For more information, please read this forum thread (and all replies).

I also ran across a similar problem last night as was able to replicate the issue discussed in the aforementioned thread. In short, you have to do an update e-mail request without any List assignments. Then, after a successful update e-mail request do a second request to re-assign the contact to a list(s).

I hope Contstant Contact resolves this soon because it is a real pain to have to do double calls when updating an e-mail address to preserve contact history.

Regular Participant


 Is it possible to post a sample code for update.?

it would be very helpful.



I know this is an old thread, but I am experiencing this issue when I try to update my contacts through the API.  It will update fine, but if I include a changed e-mail address it inserts a new record.  


To do the udpate, I GET the XML for the user using their UserId.  THen I modify the XML with the updated values. Then I PUT the user informaiton.  


If I don't include the e-mail address the user gets updated.  If I include the new e-mail address a new user gets added.


I would prefer not to remove the user and then re-add them.



I am going to look into the C# wrapper to see what the problem is.  I will post back here with what I find.  Thanks for your patience.


Best Regards,

Shannon W.

API Support Specialist



I troubleshooted in RESTclient, doing a GET for the contact, and then PUTting their modified XML back with the new email address.  I included the new email address in the PUT to try to reproduce what you're seeing, with a new contact getting created instead of updating the existing one, but that doesn't happen in my account.  You are using the same contact ID for the contact, right?


Would you mind posting the XML you're using here, with your credentials and email addresses omitted?  You can also email it to us at webservices@constantcontact.com so that we can take a look and try to reproduce what you're seeing.



Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page