cancel
Showing results for 
Search instead for 
Did you mean: 

Error 400 - Bad Request

Highlighted
Advisor

Error 400 - Bad Request

Hi, I've attached an XML file that returns an Error 400 - Bad Request when run with a "Put".  The routine that builds this is pretty generic and works for 99.999% of the records so I'm wondering what the problem might be with this one.

 

Please let me know if you need more information.

 

Thanks.

 

Chris Campbell

Cascade Data Solutions

 

3 REPLIES 3
Honored Contributor

Re: Error 400 - Bad Request

Hi Chris,

 

After investigating this issue, it appears that what is happening is that the account you are executing the PUT request against does not contain a list with the ID of 1. This is due to a change that was made in our new contact management system that causes all new lists to have a truly unique account. Because the account that you are working with on this request was created very recently, it would have defaulted to the new management system and the General Interest list will have a unique numeric ID, rather than a default ID of 1.

 

You can get around this issue by performing an initial GET request to http://api.constantcontact.com/ws/customers/<username>/lists and using the response to get the ID of the list you want to use. Once you have that ID, you can input it into your XML code as shown in this code snippet by <LISTID>:

 

<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/<username>/lists/<LISTID>">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/<username>/lists/<LISTID>" rel="self"></link>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<OptInTime>2014-05-16T19:50:50.000Z</OptInTime>
</ContactList>
</ContactLists>

 

If you are still experiencing any issues after this, please let us know and we will be happy to assist you!

 

Best Regards, 

Elijah G.
API Support Engineer
Advisor

Re: Error 400 - Bad Request

Hello Elijah,

 

I was able to verify that the bad request message did not originate from an invalid List ID because all the list ID's that I download from CC match up to the list ID's I have assigned in my application.  The same holds true for the Contact ID's.  

 

I'm attaching three XML files.  The first one is a listing of all contacts that I downloaded from CC, the second one is a listing of all Lists that I downloaded from CC, and the third one is an XML request that is returning "Bad Request" when issuing a PUT.  I've verified that the ID's being used are correct based on what CC is telling me is the correct ID.

 

The information in these files is from one of our test accounts that we use and does not contain "real" data so no worries on running it.

 

Thanks for looking at it.

 

Chris

Honored Contributor

Re: Error 400 - Bad Request

Hi Chris,

 

After some testing, I found two issues that were causing 400 errors:

 

1. the CountryCode field is a field with limited length text content, and it does not behave well with a newline and multiple spaces in the content. Here is the fix.

 

Before: 

<CountryCode>
      </CountryCode>

 After:

<CountryCode></CountryCode>

 

2. Your StateCode and StateName fields have the same value. This is causing an issue, as one is meant ot be a full state name while the other is a two-letter code. Here is the fix for that.

 

Before:

      <StateCode>NE</StateCode>
      <StateName>NE</StateName>

After:

      <StateCode>NE</StateCode>
      <StateName>Nebraska</StateName>

 

Once these two adjustments are made, then the contact will update properly resulting in a 204 response.

 

One important note here is that You can troubleshoot these issues by making sure that you collect the HTTP response body and not just the code when you receive a 400 error. Our API is designed to send back an error describing the issue in the response body any time a 400 error occurs.

 

If you are still running into any issues after making these changes, please let me know and I will be happy to help.

 

Best Regards,

Elijah G.
API Support Engineer