Hello,
In your script, is $tmpfile a file handle for a temporary file, or is the XML string going directly into the $tmpfile string? If the latter, this typically doesn't work with PHP cURL PUT requests, and I confirmed our API will return the 400 error you repoted.
The XML you are using is fine, based on my testing, but your request code may need a little tweaking. I was able to get the request to fly in in my test account by first putting xml into the string $entry, and writing it to a temporary file ($tmpfile) using the tmpfile() function, so instead of a string variable, $tmpfile is actual the handle for the temporary file. For convenience, I also made a small change to how the CURLOPT_USERPWD is set up in your code, resulting in the following working example:
<?php
$entry = 'THE_XML';
$tmpfile = tmpfile();
fwrite($tmpfile, $entry);
fseek($tmpfile, 0);
// Put your API Key, Username and Password here
$auth = $API_Key."%".$username.":".$password;
// Initialize the curl session
$request ="https://api.constantcontact.com/ws/customers/{username}/contacts/{user ID}";
$session = curl_init($request);
curl_setopt($session, CURLOPT_USERPWD, $auth);
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_INFILE, $tmpfile);
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);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($session);
$httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session);
?>
I hope this helps you get your PUT requests rolling.
Cheers,
... View more