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.

Error 400: The request contains errors in the common Atom sections

Highlighted
New Member

Error 400: The request contains errors in the common Atom sections

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

1 REPLY 1
Highlighted
Employee

Re: Error 400: The request contains errors in the common Atom se

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

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