PHP Contact List PUT giving 401

Occasional Participant

PHP Contact List PUT giving 401

I am tryingt o update a contact for a registration page. Basically i have 2 scenarios.

1. A user signs up and does not exist in the system. This case the user is added and signed up to the list, this works fine.

2. A user already exists and is not signed up for the list. This case i need to retrieve the user contact lists, and update the record with the new registration data and add them to the new list.

I am getting a 401 error when i try to update the user, i am following the sample code here

My issue seems to be when i try to PUT the entry back and update it.

My Code is as follows:

$entry = ''.$UN.'/contacts/'.$SubID.'
Contact: ' . $email . '

' . $email . '
' . $first_name . '
' . $last_name . '
' . $company . '
' . $title . '
' . $address . '
' . $address2 . '
' . $city . '
' . $state . '
' . $zip . '
' . $seminar1 . '
' . $seminar2 . '
' . $seminar3 . '

'. $contact_list_xml .'


//echo "
// create a temp file and load the xml in to it.
$tmpfile = tmpfile();
fwrite($tmpfile, $entry);
fseek($tmpfile, 0);

// Initialize the curl session
$request ="".$UN."/contacts/".$SubID;
$session2 = curl_init($request);

curl_setopt($session2, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($session2, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session2, CURLOPT_INFILE, $tmpfile);
fclose($tmpfile); // Close temp file because it no longer needed

curl_setopt($session2, CURLOPT_PUT, 1);
curl_setopt($session2, CURLOPT_INFILESIZE, strlen($entry));
curl_setopt($session2, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session2, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($session2, CURLOPT_RETURNTRANSFER, 0);
$response = curl_exec($session2);
$httpcode = curl_getinfo($session2, CURLINFO_HTTP_CODE);
if ($httpcode > 199 && $httpcode < 300)
echo "It works!!" ; // You might want GET the updated Contact and display it
{ echo "
There a Problem
Error Code: ". $httpcode ; }


Output is:

HTTP/1.1 401 Unauthorized
Date: Wed, 13 May 2009 21:18:46 GMT
Server: IBM_HTTP_Server
WWW-Authenticate: OAuth realm=""
WWW-Authenticate: Digest realm="", nonce="324b0c0ae0925e45d55bf4284f216ced", qop="auth"
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Set-Cookie: BIGipServerProdAPI=2286162954.20480.0000; path=/

HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
Date: Wed, 13 May 2009 21:18:46 GMT
Server: IBM_HTTP_Server
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html; charset=ISO-8859-1
Content-Language: en-US

There a Problem
Error Code: 400

Any help is greatly appreciated, thanks,

Occasional Participant

I was missing the <updated> tag in the entry.

Kinda silly..

Everything all set Chris? Sounds like you found the problem but I wanted to make sure everything was ok.
Dave Berard
Senior Product Manager, Constant Contact


I'm having the exact same woes, and although I understand the process of the GET & update, my php is so rusty I'd hate to attempt writing this for a simple landing page we're doing. I'd love to have a look at the main script that first checks to see if they exist in CC and then updates or adds.

I have the API working like a dream while only adding contacts, but not getting them on a new list.

Any help would be appreciated! Thanks, Ben

Developer Portal

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

Visit Page