The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Getting a XML Malformed message when attempting to add contact

SOLVED
Go to solution
Highlighted
Occasional Contributor

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.

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Employee

Re: Getting a XML Malformed message when attempting to add contact

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
Highlighted
Employee

Re: Getting a XML Malformed message when attempting to add contact

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

Highlighted
Occasional Contributor

Re: Getting a XML Malformed message when attempting to add contact

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured