Between 9pm - 11pm ET this Sat (9/18), we will be doing routine network maintenance. Please avoid usage of our API during this time frame - including any scheduled sync jobs. Thank you in advance for your patience.

Error 400 - Bad Request

Regular Participant

Error 400 - Bad Request


I keep hitting this error 400 - Bad Request if I try to add a new list or add a new contact to existing list. I tried the GET function and it worked beautifully so I know there is nothing wrong with the siteurl, username, password and API Key. Please take a look at the code below.

public void AddList()





                    // Create LoginCreditials

                    CredentialCache LoginCredentials = new CredentialCache();


                    // Add a new credential for this account

                    LoginCredentials.Add(new Uri(""),

                                                "Basic", new NetworkCredential("xxx-MyKey-xxx" +

                                                "%" + "myusername", "mypassword"));


                    string sUri = "";

                    //Setup an HttpWebRequest to send the data

                    Uri addresss = new Uri(sUri);

                    HttpWebRequest request = WebRequest.Create(addresss) as HttpWebRequest;

                    request.Credentials = LoginCredentials;

                    request.Method = "POST";

                    request.ContentType = "application/atom+xml";                                      

                    StringBuilder requestParam = new StringBuilder();

                    requestParam.Append("OptInDefault=" + HttpUtility.UrlEncode("false"));

                    requestParam.Append("&Name=" + HttpUtility.UrlEncode("NewList"));

                    requestParam.Append("&ShortName=" + HttpUtility.UrlEncode("NewL"));

                    requestParam.Append("&DisplayOnSignup=" + HttpUtility.UrlEncode("No"));

                    requestParam.Append("&SortOrder=" + HttpUtility.UrlEncode("92"));                  


                    //The response (returned as 'strResponse') will be XML. You can parse this for status messages if you like, or just ignore it.

                    byte[] byteData = UTF8Encoding.UTF8.GetBytes(requestParam.ToString());

                    string st = string.Empty;

                    request.ContentLength = byteData.Length;

                    using (Stream postStream = request.GetRequestStream())


                        postStream.Write(byteData, 0, byteData.Length);


                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)


                        StreamReader reader = new StreamReader(response.GetResponseStream());

                        st = reader.ReadToEnd();



                catch (WebException e)


                    // Get the web exception type and response code

                    MessageBox.Show(e.Status + "With response:" + e.Message);


                catch (Exception e)


                    // Get the exception type




Any suggestions?




Hi Kavita,


The reason you are receiving 400 requests is that the data you are sending is not a well formed XML request to add or update a contact.  You can find out more information on how to create the structure of the XML here.  I would recommend checking our our ASP.NET sample code, which is written in C#, instead as it will probably save you alot of time developing.  You can find the sample code here.  

Dave Berard
Senior Product Manager, Constant Contact
Regular Participant

The Sample code really helped.

Thanks Dave!

Developer Portal

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

Visit Page