Hello.
I am trying to link my website to constant contact, but the problem is that I have an error.
(Error 400: The request contains errors in the common Atom sections, which lie outside or , such as , , or.)
I found on internet that it was about my XML file. So is it correct or is it an other problem ?
$date = date("Y-m-d\TH:i:s");
$theXml = <<<THE__XML
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"></title>
<updated>2008-07-23T14:21:06.407Z</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>$mail</EmailAddress>
<FirstName>$f_name</FirstName>
<LastName>$l_name</LastName>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactList id="http://api.constantcontact.com/ws/customers/XXXXXXX/lists/1" />
</Contact>
</content>
</entry>
THE__XML;
$ch = curl_init();
$UN = "XXXXXXX";
$PW = "XXXXXXX";
$Key = "XXXXXXX";
$userNamePassword = $Key . '%' . $UN . ':' . $PW;
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $userNamePassword);
//curl_setopt($ch, CURLOPT_USERPWD, $UN.":".$WP);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS , $theXML);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set the url to fetch
curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/XXXXXXX/contacts');
$content = curl_exec($ch);
// remember to always close the session and free all resources
curl_close($ch);
echo $content;
Thanks a lot. Jérémy
Hi Jérémy,
This will work with just a few slight modifications.
1. Add the curl option:
'curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);'
2. Wrap you make your <ContactList> node an element of <ContactLists>. For example:
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/XXXXXXX/lists/1" />
</ContactLists>
Also note that PHP is case-sensitive - it looks like you are posting "$theXML" and your Xml is being saved as "$theXml".
You can add multiple <ContactList> nodes to subscribe the contact to more than one list. I hope that this helps. Please let me if this solves the 400 error you've been receiving.
David J