cancel
Showing results for 
Search instead for 
Did you mean: 

Error 400 on Update Contact / can you check my XML please?

Highlighted
Occasional Contributor

Error 400 on Update Contact / can you check my XML please?

I'm doing a "PUT" against this URL:

https://api.constantcontact.com/ws/customers/{username}/contacts/5?access_token=abc123

This is my XML (username was suppressed):
<entry xmlns="http://www.w3.org/2005/Atom">
  <title> </title>
  <updated>2008-04-25T19:29:06.096Z</updated>
  <author> </author>
  <id>http://api.constantcontact.com/ws/customers/{username}/contacts/5</id>
  <content type="application/vnd.ctct+xml">
    <Contact xmlns=" http://ws.constantcontact.com/ns/1.0/" id=" http://api.constantcontact.com/ws/customers/{username}/contacts/5>
      <EmailAddress>my@emaildomain.com</EmailAddress>
      <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/1"></ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/2"></ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/3"></ContactList>
        </ContactLists>
    </Contact>
  </content>
</entry>

This is the response:
Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

Can you help me fix my XML? All I want to do is add the contact to the list-id's I'm providing.

6 REPLIES 6
CTCT Employee

Re: Error 400 on Update Contact / can you check my XML please?

Hi,

 

You are using the minimum XML required to create a contact.  Your XML would be fine if the contact didn't already exist, but when updating a contact, you actually have to include all of the XML elements available for a contact.  The best way to see what those are is to do a GET on the contact, update the fields you want to edit, and then do your PUT.

 

Let me know if you want any clarification.  Your XML should look roughly like below when you PUT it.

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/username/contacts/1" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/username/contacts/1</id>
  <title type="text">Contact: example@example.com</title>
  <updated>2012-09-12T16:38:10.714Z</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/1">
      <Status>Active</Status>
      <EmailAddress>example@example.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name>Test1 Test1</Name>
      <FirstName>Test1</FirstName>
      <MiddleName></MiddleName>
      <LastName>Test1</LastName>
      <JobTitle></JobTitle>
      <CompanyName></CompanyName>
      <HomePhone></HomePhone>
      <WorkPhone></WorkPhone>
      <Addr1></Addr1>
      <Addr2></Addr2>
      <Addr3></Addr3>
      <City>Orlando</City>
      <StateCode>FL</StateCode>
      <StateName>Florida</StateName>
      <CountryCode>us</CountryCode>
      <CountryName>United States</CountryName>
      <PostalCode></PostalCode>
      <SubPostalCode>M</SubPostalCode>
      <Note></Note>
      <CustomField1>beautiful home with lots of privacy</CustomField1>
      <CustomField2>help millions of people every day</CustomField2>
      <CustomField3>09</CustomField3>
      <CustomField4>18</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/username/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username/lists/1" rel="self"></link>
          <OptInSource>ACTION_BY_CONTACT</OptInSource>
          <OptInTime>2012-09-04T14:21:59.048Z</OptInTime>
        </ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/username/lists/18">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username/lists/18" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-09-10T13:45:15.863Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-01-11T14:19:52.048Z</InsertTime>
      <LastUpdateTime>2012-09-12T16:38:10.714Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/username/contacts</id>
    <title type="text">Contacts for Customer: username</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>username</name>
    </author>
    <updated>2012-09-20T13:39:18.959Z</updated>
  </source>
</entry>

 

 

Best Regards,

Shannon W.

API Support Specialist

Occasional Contributor

Re: Error 400 on Update Contact / can you check my XML please?

(a) is this documented anywhere? This page is horrible: http://community.constantcontact.com/t5/Documentation/Updating-Contact-Information/ba-p/25055

 

(b) Your answer needs clarification; you say two things: "you actually have to include all of the XML elements available for a contact" and then you give me the very long example XML. Is your example *litterally* what I should use? OR, are you saying, whatever is returned bythe GET is what I should use in the PUT?

 

(c) Here's my updated XML; it still doesn't work:

 

GET Contact 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">Contacts for Customer: {username}</title>
  <link href="contacts"></link>
  <link href="contacts" rel="self"></link>
  <author>
    <name>{username}</name>
  </author>
  <updated>2012-09-23T20:07:15.627Z</updated>
  <link href="/ws/customers/{username}/contacts" rel="first"></link>
  <link href="/ws/customers/{username}/contacts?email=some-email@some-domain.com&amp;access_token={access-token}" rel="current"></link>
  <entry>
    <link href="/ws/customers/{username}/contacts/5" rel="edit"></link>
    <id>http://api.constantcontact.com/ws/customers/{username}/contacts/5</id>
    <title type="text">Contact: some-email@some-domain.com</title>
    <updated>2012-09-23T20:07:15.636Z</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/5">
        <Status>Active</Status>
        <EmailAddress>some-email@some-domain.com</EmailAddress>
        <EmailType>HTML</EmailType>
        <Name></Name>
        <OptInTime>2012-09-19T15:53:37.976Z</OptInTime>
        <OptInSource>ACTION_BY_CONTACT</OptInSource>
        <Confirmed>true</Confirmed>
        <InsertTime>2012-09-19T15:53:37.976Z</InsertTime>
      </Contact>
    </content>
  </entry>
</feed>


PUT Contact XML:
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/username/contacts/1" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/username/contacts/1</id>
  <title type="text">Contact: some-email@some-domain.com</title>
  <updated>2012-09-23T15:07:15Z</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/5">
      <Status>Active</Status>
      <EmailAddress>some-email@some-domain.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name></Name>
      <OptInTime>2012-09-19T15:53:37.976Z</OptInTime>
      <OptInSource>ACTION_BY_CONTACT</OptInSource>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/{username}/lists/1" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-09-23T15:07:15Z</OptInTime>
        </ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/2">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/{username}/lists/2" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-09-23T15:07:15Z</OptInTime>
        </ContactList>
        <ContactList id="http://api.constantcontact.com/ws/customers/{username}/lists/3">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/{username}/lists/3" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2012-09-23T15:07:15Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-01-11T14:19:52.048Z</InsertTime>
      <LastUpdateTime>2012-09-23T15:07:15Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/{username}/contacts</id>
    <title type="text">Contacts for Customer: {username}</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>{username}</name>
    </author>
    <updated>2012-09-23T15:07:15Z</updated>
  </source>
</entry>

 

Note: I also tried it using your *exact* example and the same error was returned:

 

Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

 

I'm really close to giving up on this integration, thank you for your help.

CTCT Employee

Re: Error 400 on Update Contact / can you check my XML please?

Hi,

 

Sorry for the frustration.  You are right, that page isn't very helpful, and I apologize.  The third section of this page shows all of the fields that you should have for a contact.

 

It doesn't look like you are getting back everything you should when you do a GET for a contact.  You should be returned all of the possible nodes for a contact when you do a GET, even empty custom fields, etc.  One of the main problems with the XML you are trying to PUT is that there are nodes that aren't organized according to our examples, such as the OptInSource and OptInTime.  Those shouldn't be within the ContactLists node; they should be outside it.

 

I can't show you EXACTLY what you should PUT for a contact--you should do a get and then put the information back with your updates, not use my example exactly, because it won't reference your username, the contact's unique ID, email address, or lists in your account that it should belong to.  What I posted was organizationally what you should be putting for a contact, however.  

 

If you aren't getting ALL of the fields listed in the last XML example in the link I referenced above, there is something wrong.  If that's the case, the information is getting lost somewhere and I would recommend troubleshooting with RESTClient.

 

Best Regards,

Shannon W.

API Support Specialist

Moderator

Re: Error 400 on Update Contact / can you check my XML please?

Hey Brian,

 

The specific portion of this XML that is giving the error is a small mismatch in your contact ID's. The first link and ID in your PUT XML is directed to /contacts/1, and the rest of the XML is directed to /contacts/5. I've tested your XML using these changes, and things are working on my end. If you're still having issues, just reply back and we'll help however we can!

Nick Galbraith
Support Engineer
Occasional Visitor

Re: Error 400 on Update Contact / can you check my XML please?

I'm having exactly the same problem, I'm getting the 400 error when trying to update a contact even when I put exactly the same XML that is returned when getting the contact's details with the URL: https://api.constantcontact.com/ws/customers/{username}/contacts/{ContactIDNumber}

 

Any ideas? Any help would be appreciated it.

CTCT Employee

Re: Error 400 on Update Contact / can you check my XML please?

Hi,

 

I would like to take a look at your XML.  Could you remove your username and email address from the xml and post it here, or email it to webservices@constantcontact.com?  Just to be clear, you are doing a GET for the contact, then doing a PUT to update the contact, right?

 

Could you also include the URI that you are PUTting to, with just the username removed?  Above, the issue was that there was a mismatch in the contact's ID, which is referenced in the XML and URI.

 

Best Regards,

Shannon W.

API Support Specialist