We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

400 error common atom issues

Regular Participant

400 error common atom issues


I'm getting these 400 errors saying that my atom stuff is a no go.  I have verified the structure, and that I'm using my default atom nodes.  Here is my action.  Anybody got any clues?

$newEmail = $_POST;

$date = date("Y-m-d\TH:i:s");

$theXml = <<<THE__XML

<entry xmlns="http://www.w3.org/2005/Atom">

<title type="text">Contact Stuff</title>




<summary type="text">Contact</summary>

<content type="application/vnd.ctct+xml">

<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/contacts">




<ContactList id="http://api.constantcontact.com/ws/customers/username/lists/13" />






$ch = curl_init();

$UN = "username";

$PW = "password";

$Key = "blahblahblah";

$userNamePassword = $Key . '%' . $UN . ':' . $PW;


curl_setopt($ch, CURLOPT_USERPWD, $userNamePassword);

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/username/contacts');

$content = curl_exec($ch);

// remember to always close the session and free all resources


echo $content;



Hi, I looked at your posting because I was getting similar errors.  In my case it was because I was trying to fetch a contact using a POST (should have used a GET, stupid transcribing error on my part).  In your case I see one big problem.  In your line:

curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/username/contacts');

you should be using the actual user-name, not the string 'username'.

--- Cliff Janson, independent consultant (http://comparehybridcars.net/cliff-janson.html)

Regular Participant

Hi Cliff,

Well, I'm not trying to fetch a contact, I'm trying to add a contact and that, I think is a POST.  Also, i have username because i didnt want to give out the real user.  thanks for your help though, any other ideas?  Anybody from CC have some input?




Not applicable

I compared your XML with what we recommend when creating a new contact, shown in http://developer.constantcontact.com/doc/manageContacts#create_contact, and found two things you might want to try:

1. Please double check your date format to make sure it matches the format used in the example XML, including milliseconds and "Z" at the end

2. Please change the value of <id> tag to what's used in the example., which is "data:,none".

The XML that's listed in the above link is what works when you try to create a contact.  You should only have to change the values inside <content> tag and shouldn't have to touch anything else. 

Regular Participant

Ok, made the changes you said may be causing the problem and still nothing.  Here is an output of the xml I'm sending with the response right below.  

<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text">Oread Contact</title>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">

<ContactList id="http://api.constantcontact.com/ws/customers/Robinski66/lists/13" />
Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.
Occasional Participant

I looked at my code that adds a contact (and which is working) and noticed a couple things:

In my curl options, I am using two that you are not:

curl_setopt($session, CURLOPT_FOLLOWLOCATION ,1);

curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);

Might these matter to your error? Don't know.

Also in building my XML, a few other minor differences:

- I am using <OptInSource>ACTION_BY_CUSTOMER</OptInSource>

- My <title> node is empty: <title type="text"> </title>

- I am not supplying ms in the time in the <updated> node, I use PHP date('Y-m-d\TH:i:s\Z')

- I am supplying first and last name nodes in addition to email

Otherwise, I am doing exactly what you are.

Regular Participant

Thanks for the ideas... tried making those changes too, and still nothing.....  Anybody work at Constant Contact?  Any developers that might have a second to help me out with this? 


After looking at your code it looks as though your variable containing the XML is set as $theXml however in the cURL request you a referencing $theXML.


This, along with the changes that JSJ suggested should resolve your issue.

Dan H

Support Engineer, Constant Contact

Developer Portal

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

Visit Page