cancel
Showing results for 
Search instead for 
Did you mean: 

Update in Constant contact

Occasional 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


 


 


 


$first_name="hahaha";

$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">

  <id>http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'</id>

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

  <updated>2008-04-25T19:29:06.096Z</updated>

  <author><name></name></author>

  <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.'">

      <EmailAddress>harihariha1@3examghfghplexcvxc.com</EmailAddress>

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

      <LastName>pilla</LastName>

      <OptInSource>ACTION_BY_CUSTOMER</OptInSource>

      <ContactLists>

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

        </ContactList>

      </ContactLists>

    </Contact>

  </content>

</entry>';



/*

    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:

    <ContactLists>

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

            </ContactList>

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

            </ContactList>

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

            </ContactList>

    </ContactLists>

*/



// 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_HTTPAUTH, CURLAUTH_DIGEST);

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

curl_close($session);

var_dump($httpcode);

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

    {

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

 }

else

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



?>


 


 


 


 


Could u please help me to figure out this issue


thanks


Aravind.R

6 REPLIES 6
CTCT Employee

Update in Constant contact

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

New Member

RE: Update in Constant contact

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

Occasional Participant

Hi  Is it possible to post a

Hi


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


it would be very helpful.


Aravind.R

Regular Visitor

Re: Update in Constant contact

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.

Highlighted
CTCT Employee

Re: Update in Constant contact

Hi,

 

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

CTCT Employee

Re: Update in Constant contact

Hi,

 

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