Reply
Occasional Participant
shizny
Posts: 4
Registered: ‎02-12-2010

400 error common atom issues

Hello,


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>

<updated>$date</updated>

<author></author>

<id>http://api.constantcontact.com/ws/customers/username/contacts</id>

<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">

<EmailAddress>$newEmail</EmailAddress>

<OptInSource>ACTION_BY_CONTACT</OptInSource>

<ContactLists>

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

</ContactLists>

</Contact>

</content>

</entry>

THE__XML;



$ch = curl_init();



$UN = "username";

$PW = "password";

$Key = "blahblahblah";

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



curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

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

curl_close($ch);

echo $content;

 

New Member
CliffJanson
Posts: 1
Registered: ‎08-18-2009

errors in the atom section

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)

Occasional Participant
shizny
Posts: 4
Registered: ‎02-12-2010

No Go on that one

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?


 


:)


Josh 

Anonymous(anon)
Posts: 0

I compared your XML with what

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. 

Occasional Participant
shizny
Posts: 4
Registered: ‎02-12-2010

Still nothing

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>
<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>test_100@example.com</EmailAddress>
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<ContactLists>


<ContactList id="http://api.constantcontact.com/ws/customers/Robinski66/lists/13" />
</ContactLists>
</Contact>
</content>
</entry>
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
JSJ
Posts: 3
Registered: ‎02-17-2010

A few other ideas

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.

Occasional Participant
shizny
Posts: 4
Registered: ‎02-12-2010

still no go

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? 

CTCT Employee
DanHoran
Posts: 178
Registered: ‎06-26-2009

After looking at your code it

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