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 when updating contact's info

Highlighted
Occasional Participant

Error 400 when updating contact's info

Hello!

 

I've been trying to make a script that updates the contact's information, I've downloaded the Sample Code provided and modified them to my needs. The XML generated for modifiying the contac's info is:

 

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

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

<title>TitleNode</title>

<updated>2012-05-14T12:56:51+01:00</updated>

<author>

<name>CTCT Samples</name>

</author>

<id>476</id>

<summary type="text">Customer document</summary>

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

<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">Customer document

<EmailAddress>user@example.com</EmailAddress>

<FirstName>FirstName</FirstName>

<LastName>LastName</LastName>

<MiddleName></MiddleName>

<CompanyName></CompanyName>

<OptInSource>ACTION_BY_CUSTOMER</OptInSource>

<HomePhone></HomePhone>

<WorkPhone></WorkPhone>

<Addr1></Addr1>

<Addr2></Addr2>

<Addr3></Addr3>

<City></City>

<StateCode></StateCode>

<StateName></StateName>

<CountryCode></CountryCode>

<PostalCode></PostalCode>

<SubPostalCode></SubPostalCode>

<Note></Note>

<EmailType>HTML</EmailType>

<ContactLists>

<ContactList id="21"/>

</ContactLists>

</Contact>

</content>

</entry>

 

But I get this error: "Error 400: The request contains errors in the common Atom sections, which lie outside or , such as , , or ."

 

I've also read the Error codes definition but as you can see the message outside blank space and such as blank space are not really helpful and the API documentation is not that usefull.. 

 

Could I please get a hint of what I'm doing wrong here?

 

Thanks in advance!

 

8 REPLIES 8
Highlighted
Moderator

Re: Error 400 when updating contact's info

Hello Carlos,

 

I'm noticing a few problems with your XML, but instead of going through and correcting these, I thought I might give a different route for updating contacts, that might help prevent future issues as well.

 

If you are updating a contact, anything that you don't include in the PUT will overwrite any existing data. Because of this, you will want to run a GET to the existing Contact record, modify the received XML, and then PUT the information back to update the contact. This will also resolve the 400 errors you are encountering, as the XML you receive will be valid in the areas that currently give the error.

Nick Galbraith
Support Engineer
Highlighted
Occasional Participant

Re: Error 400 when updating contact's info

Thanks Nick!

 

I've also tried to run a GET with a Search by email, but I'm finding quite difficult to parse the GET response to get the contact's id and modify the email and status which are basically the only fields that I want to update. I got the same 400 error when sending this XML:

 

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://api.constantcontact.com/ws/customers/username/contacts</id>
<title type="text"></title>
<link href="contacts"></link>
<link href="contacts" rel="self"></link>
<author>
<name>username</name>
</author>
<updated>2012-05-14T15:37:50.270Z</updated>
<link href="/ws/customers/username/contacts" rel="first"></link>
<link href="/ws/customers/username/contacts?email=username%40domain.com" rel="current"></link>
<entry>
<link href="/ws/customers/username/contacts/476" rel="edit"></link>
<id>http://api.constantcontact.com/ws/customers/username/contacts/476</id>
<title type="text">Contact: username@domain.com</title>
<updated>2012-05-14T15:37:50.492Z</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/username/contacts/476">
<Status>Active</Status>
<EmailAddress>'.$new_email.'</EmailAddress>           <---- There goes the new email
<EmailType>HTML</EmailType>
<Name>LASTNAME, FIRSTNAME</Name>
<OptInTime>2012-05-10T17:56:52.167Z</OptInTime>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<Confirmed>true</Confirmed>
<InsertTime>2012-05-10T17:56:52.172Z</InsertTime>
</Contact>
</content>
</entry>
</feed>

 

Thanks for your response!

Highlighted
Moderator

Re: Error 400 when updating contact's info

What language are you using to process these? I can offer some functions that I've used in the past to help with this, and we may also have a wrapper library to make these calls and functions easier.

Nick Galbraith
Support Engineer
Highlighted
Occasional Participant

Re: Error 400 when updating contact's info

Thanks for your help Nick, I'm using php to process this.

Highlighted
Occasional Participant

Re: Error 400 when updating contact's info

I was wondering if someone has a sample code on how to correctly make a PUT request with PHP, I've done it my way, the code sample way and I'm getting different errors every time... Maybe there could be my mistake.

 

Thanks in advance!

Highlighted
Trusted Contributor

Re: Error 400 when updating contact's info

Hello,

 

Our PHP Wrapper Library, once you get the hang of it, can help simplify coding for get and update requests, so I would really suggest you look into it, and consider using it for your application. Also, if you need to expand your application for additional functionality in the future, using the wrapper would facilitate that process.

 

There is a general summary of the approach for updating the contact in the wiki of the PHP Wrapper Library that should help you accomplish this without worrying much about parsing and validation issues you may face by manually coding these functions.

 

Cheers

Mark Coleman
Support Engineer
Highlighted
Occasional Participant

Re: Error 400 when updating contact's info

Thanks! I'll try it right away!

Highlighted
Trusted Contributor

Re: Error 400 when updating contact's info

It can take a bit to get your mind around how to implement the Wrapper Libraries when you're first using them, but in the long run it simplifies your programming. Feel free to let us know if you have an difficulties, and we'll do what we can to assist.

Mark Coleman
Support Engineer
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