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, which lie outside.......

SOLVED
Go to solution
Highlighted
Occasional Contributor

Error 400: The request contains errors in the common Atom sections, which lie outside.......

Hi, can anyone out there help me determine where my XML is causing this problem?  Here's the XML:

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/[removed for security]/contacts/10048" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/[removed for security]/contacts/10048</id>
  <title type="text">Contact: [removed for security]</title>
  <updated>2012-07-04T22:45:23.251Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/vnd.ctct+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/[removed for security]/contacts/10048">
      <Status>Active</Status>
      <EmailAddress>[removed for security]</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name> </Name>
      <FirstName></FirstName>
      <MiddleName></MiddleName>
      <LastName></LastName>
      <JobTitle></JobTitle>
      <CompanyName></CompanyName>
      <HomePhone></HomePhone>
      <WorkPhone></WorkPhone>
      <Addr1></Addr1>
      <Addr2></Addr2>
      <Addr3></Addr3>
      <City></City>
      <StateCode></StateCode>
      <StateName></StateName>
      <CountryCode></CountryCode>
      <CountryName></CountryName>
      <PostalCode></PostalCode>
      <SubPostalCode></SubPostalCode>
      <Note></Note>
      <CustomField1></CustomField1>
      <CustomField2></CustomField2>
      <CustomField3></CustomField3>
      <CustomField4></CustomField4>
      <CustomField5></CustomField5>
      <CustomField6></CustomField6>
      <CustomField7></CustomField7>
      <CustomField8></CustomField8>
      <CustomField9></CustomField9>
      <CustomField10></CustomField10>
      <CustomField11></CustomField11>
      <CustomField12></CustomField12>
      <CustomField13></CustomField13>
      <CustomField14></CustomField14>
      <CustomField15></CustomField15>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/[removed for security]/lists/1" rel="self"></link>
          <OptInSource>ACTION_BY_CONTACT</OptInSource>
          <OptInTime>2012-07-04T22:45:23.285Z</OptInTime>
        </ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/[removed for security]/lists/2">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/[removed for security]/lists/2" rel="self"></link>
          <OptInSource>ACTION_BY_CONTACT</OptInSource>
          <OptInTime>2011-04-05T17:51:30.656Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-04-05T17:51:30.653Z</InsertTime>
      <LastUpdateTime>2012-07-04T22:45:23.251Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/[removed for security]/contacts</id>
    <title type="text">Contacts for Customer: [removed for security]</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>[removed for security]</name>
    </author>
    <updated>2012-07-05T02:47:03.753Z</updated>
  </source>
</entry>

 

Any help is appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Trusted Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

No, it is not.  I've run many successful requests with and without it.  I'm glad it's now working for you.  Let us know if you have any other questions.

 

Cheers,

Mark Coleman
Support Engineer

View solution in original post

5 REPLIES 5
Highlighted
Trusted Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

Hello,

 

I just used the XML you provided to successfully update a contact in a test account using a PUT request. Did you recieve the error with the XML while making a request to update this contact (say, to make changes or add list memberships to the contact record?

Mark Coleman
Support Engineer
Highlighted
Occasional Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

Hi Mark,

 

Yes, I was trying to update the contact ID in the XML using a PUT request.

 

Here's the request:

       // Initialize the curl session
       $request ="https://api.constantcontact.com/ws/customers/[removed for security]/contacts/10048";

       $session = curl_init($request);

       // Set up Digest authentication. Put your API key, and CTCT username/pwd here
        curl_setopt($session, CURLOPT_USERPWD, "REDACT");
        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);

 

$tmpfile is the file XML string.

 

Highlighted
Trusted Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

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,

Mark Coleman
Support Engineer
Highlighted
Occasional Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

Hi Mark,

 

Once I removed the

 

<?xml version=\"1.0\" encoding=\"UTF-8\"?>

 

tag from befor the <entry> tag, everything worked swimmingly.  Is that line required?

 

Thanks for all of your help.

 

Joanne

Highlighted
Trusted Contributor

Re: Error 400: The request contains errors in the common Atom sections, which lie outside.......

No, it is not.  I've run many successful requests with and without it.  I'm glad it's now working for you.  Let us know if you have any other questions.

 

Cheers,

Mark Coleman
Support Engineer

View solution in original post

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