Contact Update Bad Request

Highlighted
New Member

Contact Update Bad Request

I am trying to impliment the Update Contact API and am running into "HTTP Error 400: Bad Request" errors.

 

According to the sparse API documentation on updating contacts I should be getting the Contact, changing the xml body and sending it back up. So, First I GET the contact I want to update, the following is returned:

 

<?xml version='1.0' encoding='utf-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'>
  <id>http://api.constantcontact.com/ws/customers/wsmailes/contacts</id>
  <title type='text'>Contacts for Customer: wsmailes</title>
  <link href='contacts'/>
  <link href='contacts' rel='self'/>
  <author>
    <name>wsmailes</name>
  </author>
  <updated>2012-02-05T16:33:36.381Z</updated>
  <link href='/ws/customers/wsmailes/contacts' rel='first'/>
  <link href='/ws/customers/wsmailes/contacts?email=francis@teamcolab.com' rel='current'/>
  <entry>
    <link href='/ws/customers/wsmailes/contacts/13890' rel='edit'/>
    <id>http://api.constantcontact.com/ws/customers/wsmailes/contacts/13890</id>
    <title type='text'>Contact: francis@teamcolab.com</title>
    <updated>2012-02-05T16:33:36.390Z</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/wsmailes/contacts/13890'>
        <Status>Active</Status>
        <EmailAddress>francis@teamcolab.com</EmailAddress>
        <EmailType>HTML</EmailType>
        <Name/>
        <OptInTime>2011-12-29T17:40:57.565Z</OptInTime>
        <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
        <Confirmed>true</Confirmed>
        <InsertTime>2011-12-29T17:40:57.565Z</InsertTime>
      </Contact>
    </content>
  </entry>
</feed>

 

Then I modify the XML body:

 

<?xml version='1.0' encoding='utf-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'>
  <id>http://api.constantcontact.com/ws/customers/wsmailes/contacts</id>
  <title type='text'>Contacts for Customer: wsmailes</title>
  <link href='contacts'/>
  <link href='contacts' rel='self'/>
  <author>
    <name>wsmailes</name>
  </author>
  <updated>2012-02-05T16:32:35.143Z</updated>
  <link href='/ws/customers/wsmailes/contacts' rel='first'/>
  <link href='/ws/customers/wsmailes/contacts?email=francis@teamcolab.com' rel='current'/>
  <entry>
    <link href='/ws/customers/wsmailes/contacts/13890' rel='edit'/>
    <id>http://api.constantcontact.com/ws/customers/wsmailes/contacts/13890</id>
    <title type='text'>Contact: francis@teamcolab.com</title>
    <updated>2012-02-05T16:32:35.157Z</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/wsmailes/contacts/13890'>
        <Status>Active</Status>
        <EmailAddress>francis@teamcolab.com</EmailAddress>
        <EmailType>HTML</EmailType>
        <Name/>
        <OptInTime>2011-12-29T17:40:57.565Z</OptInTime>
        <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
        <Confirmed>true</Confirmed>
        <InsertTime>2011-12-29T17:40:57.565Z</InsertTime>
        <LastName>Yaconiello</LastName>
        <FirstName>Francis</FirstName>
        <ContactList>
          <ContactList id='http://api.constantcontact.com/ws/customers/wsmailes/lists/8'/>
        </ContactList>
      </Contact>
    </content>
  </entry>
</feed>

HTTP method: PUT

URL: https://api.constantcontact.com/ws/customers/wsmailes/contacts/13890

Headers: {'Content-length': '1652', 'Content-type': 'application/atom+xml', 'Authorization': 'Basic ***************'}

response: HTTP Error 400: Bad Request

 

Any idea whats going on?

 

My class is written in python and uses urllib2, and minidom standard libraries. Thanks in advance.

 

1 REPLY 1
Highlighted
Moderator

Re: Contact Update Bad Request

The problem you're seeing is that the XML you are sending in the PUT request is the returned XML from our search API.  This API does not return a full Contact XML request, it returns a collection of all search results that we found.  You would need to do one of two things before sending back the XML in a PUT to update the Contact:

 

1. Modify the XML to be the correct XML format for a Contact Update

2. Retrieve the full XML for the Contact via the ID of the Contact results in the collection

 

Both of these options would get you past the 400 error, which would correctly be returned based of the XML you're sending.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured