Getting a XML Malformed message when attempting to add contact

SOLVED
Go to solution
FFAPF118
Regular Participant

Getting a XML Malformed message when attempting to add contact

Not sure why XML is returning as Malformed when adding new contact. Here's my php. Note, this WAS working as of yesterday, but since my cc_class.php was updated with a correct username, it no longer works... confusing, I know:

 

$posturl = "https://api.constantcontact.com/ws/customers/{$login}/contacts";
$authstr = $apikey . '%' . $login . ':' . $password;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $authstr);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post->asXML());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/atom+xml"));
curl_setopt($ch, CURLOPT_HEADER, 1); // Do not return headers

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If you set this to 0, it will take you to a page with the http response
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

 

$http_status is returning as 400 XML is malformed.

1 ACCEPTED SOLUTION
Shannon_W
Employee

Hi,

 

Have you tried hard coding the username, since the issue seems to be related to the credentials?  It might shed some light on where things are going wrong in the code.  Could you post the XML that this code produces, with your username removed?

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

2 REPLIES 2
Shannon_W
Employee

Hi,

 

Have you tried hard coding the username, since the issue seems to be related to the credentials?  It might shed some light on where things are going wrong in the code.  Could you post the XML that this code produces, with your username removed?

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

FFAPF118
Regular Participant

Hard coding seemed to work. Not sure why, but I'll take it.

Developer Portal

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

Visit Page