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.

The remote server returned an error: (400) Bad Request.

Highlighted
Visitor

The remote server returned an error: (400) Bad Request.

I am using the same code on two different web sites. One works fine, the other returns a 400 error code. I'm stumped. Below is the code, and then below that, the error trace.

 

ConstantContactBO.Contact c = new ConstantContactBO.Contact();

AuthenticationData authdata = newAuthenticationData();

authdata.Username = "xyz@customer.net";

authdata.Password = "password";

authdata.ApiKey = "apikey";

c.EmailAddress = email.Trim();

c.PostalCode = zipv.Trim();

c.StateName = statev.Trim();

c.City = cityv.Trim();

ContactOptInList theList = newContactOptInList();

c.OptInSource = ContactOptSource.ActionByContact;

theList.ContactList = newContactList("1");

theList.ContactList.OptInDefault = true;

c.ContactLists.Add(theList);

ConstantContactUtility.Utility.CreateNewContact(authdata, c);

 

 

Error Message: The remote server returned an error: (400) Bad Request.

 

Stack Trace:    at System.Net.HttpWebRequest.GetResponse()

 

   at ConstantContactUtility.Utility.GetResponseStream(AuthenticationData authenticationData, Uri address, String requestMethod, String contentType, Byte[] data) in C:\Documents and Settings\dberard\My Documents\Visual Studio 2008\WebSites\RCMT\ASP Upload Forms\Development\ConstantContactUtility\Utility.cs:line 712

 

   at ConstantContactUtility.Utility.GetResponseStream(AuthenticationData authenticationData, Uri address, String requestMethod, String contentType, String data) in C:\Documents and Settings\dberard\My Documents\Visual Studio 2008\WebSites\RCMT\ASP Upload Forms\Development\ConstantContactUtility\Utility.cs:line 677

 

   at ConstantContactUtility.Utility.PostInformation(AuthenticationData authenticationData, Uri address, String data) in C:\Documents and Settings\dberard\My Documents\Visual Studio 2008\WebSites\RCMT\ASP Upload Forms\Development\ConstantContactUtility\Utility.cs:line 310

 

   at ConstantContactUtility.Utility.CreateNewContact(AuthenticationData authenticationData, Contact contact) in C:\Documents and Settings\dberard\My Documents\Visual Studio 2008\WebSites\RCMT\ASP Upload Forms\Development\ConstantContactUtility\Utility.cs:line 280

 

1 REPLY 1
Highlighted
Honored Contributor

Re: The remote server returned an error: (400) Bad Request.

Hello,

 

Based on what I see in the code you are working with, it is very likely that the site which is giving you an error is connected to a Constant Contact account which does not contain a list with the ID 1. This is a result of a change in our contact management platform that causes all lists to be created with a unique ID. Any accounts that were created after this change or which may have deleted and re-created their General Interest list will have a new ID for the General Interst group.

 

Because of the changes, you will need to find the list ID for the General Interest list in the new account to get the information that you are looking for. The easiest way to accomplish this would be to use the API through a REST client to make a simple GET request. Here's the information that you would need to do that:

 

URL: https://api.constantcontact.com/ws/customers/USERNAME/lists
Method: GET
Authorization: Basic
  Username: APIKEY%USERNAME
  Password: CTCT_PASSWORD

 

The resulting information that you will get back from the API will be an XML formatted set of lists in the account, and will include the ID of the list which you are looking for. The ID will be presented in this format: /ws/customers/USERNAME/lists/ID

 

You can then take the numeric list ID from this data and place it into your code on this line, replacing the number 1:

theList.ContactList = newContactList("1");

 

 

If you run into any issues with getting the correct list ID, please let me know!

 

Best Regards,

 

Elijah G.
API 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