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.

Bad Request 400 Error

SOLVED
Go to solution
Highlighted
Occasional Participant

Bad Request 400 Error

Hi guys, can someone take a look at this XML to see where the problem might be.

I don't know if something changed in the last few months or what, but I used to be able to create a new campaign, but now getting a bad request 400 error:

 

Also, I think I remember a tool that I could use in the past that might give me more information as to where the error might be - is that still around?

 

 

<link href="/ws/customers/custname/campaigns" rel="edit" />
<title type="text">MBOC Last Visit</title>
<updated>2011-11-30T09:22:39:037Z</updated>
- <author>
<name>custname</name>
</author>
- <content type="application/vnd.ctct+xml">
<Name>MBOC_LastVisit0939_11/30/2011</Name>
<Status>Draft</Status>
<Date>2011-11-30T09:22:39:037Z</Date>
<Subject>We Miss You</Subject>
<FromName>mvanwye@custname.com</FromName>
<ViewAsWebpage>NO</ViewAsWebpage>
<ViewAsWebpageLinkText />
<ViewAsWebpageText />
<PermissionReminder>NO</PermissionReminder>
<PermissionReminderText>You're receiving this email because of your relationship with Constant Contact. Please <ConfirmOptin><a style="color:#0000ff;">confirm</a></ConfirmOptin> your continued interest in receiving email from us.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstName</GreetingName>
<GreetingString>Greetings!</GreetingString>
<OrganizationName />
<OrganizationAddress1 />
<OrganizationAddress2 />
<OrganizationAddress3 />
<OrganizationCity />
<OrganizationState />
<OrganizationInternationalState />
<OrganizationCountry />
<OrganizationPostalCode />
<IncludeForwardEmail>NO</IncludeForwardEmail>
<ForwardEmailLinkText />
<IncludeSubscribeLink>NO</IncludeSubscribeLink>
<SubscribeLinkText />
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body><center>hello world</center></body></html></EmailContent>
<EmailTextContent><Text>sdfjsadf</Text></EmailTextContent>
<StyleSheet />
- <ContactLists>
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/lists/13" rel="self" />
</ContactList>
</ContactLists>
- <FromEmail>
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/1" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</FromEmail>
- <ReplyToEmail>
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/1" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</ReplyToEmail>
</Campaign>
</content>
- <source>
<title type="text">Campaigns for customer: custname</title>
<link href="campaigns" />
<link href="campaigns" rel="self" />
- <author>
<name>custname</name>
</author>
<updated>2011-11-30T09:22:39:037Z</updated>
</source>
</entry>
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Bad Request 400 Error

This is very confusing here on my end as I can use your XML with only a slight modification to reflect my account and this works perfectly with the content as it is.  Is it possible for you to try to replicate in the RESTClient and see if you get the same 400 error there?  If you don't, the odds are that the problem is in the C# code.  If you do, then you can save the request that gets the error and send it to us via email (webservices@constantcontact.com) and we can look at your exact request. 

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

6 REPLIES 6
Highlighted
Moderator

Re: Bad Request 400 Error

You aren't encoding the content of the <EmailContent> node, so there will be an XML validation failure that would return a 400 error (the full error message would tell you that the EmailContent node cannot be a complex type).  Any language will return our full error message but I believe the tool you're asking about for easy testing is the RESTClient that we have a post on how to use here: http://community.constantcontact.com/t5/Documentation/How-To-Use-RESTClient/ba-p/24915

 

Also, you aren't encoding the content of the <PermissionReminder> or <EmailTextContent> nodes.  Basically, the content of every XML node MUST be HTML encoded in order for it to be sent over and pass the XML validation.  If this was working before, it's like that what changed is whatever mechanism you had encoding the content of the nodes is no longer encoding it or was changed somehow.

 

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: Bad Request 400 Error

Sorry, I have gone back and forth with the code trying to fix this today that, but I have tried to do that.

I am using c#, and so using HttpUtility.HtmlEncode()

 

I still get a bad request, but here is the XML when I do that - anything else catch your eye?

Thanks so much for your help!

 

 

<?xml version="1.0" encoding="UTF-8" ?>
- <entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/custname/campaigns" rel="edit" />
<id>http://api.constantcontact.com/ws/customers/custname/campaigns</id>
<title type="text">MBOC Last Visit</title>
<updated>2011-11-30T10:53:26:110Z</updated>
- <author>
<name>custname</name>
</author>
- <content type="application/vnd.ctct+xml">
- <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/custname/campaigns">
<Name>MBOC_LastVisit1026_11/30/2011</Name>
<Status>Draft</Status>
<Date>2011-11-30T10:53:26:110Z</Date>
<Subject>We Miss You</Subject>
<FromName>mvanwye@custname.com</FromName>
<ViewAsWebpage>NO</ViewAsWebpage>
<ViewAsWebpageLinkText />
<ViewAsWebpageText />
<PermissionReminder>NO</PermissionReminder>
<PermissionReminderText>You're receiving this email because of your relationship with Constant Contact. Please &lt;ConfirmOptin>&lt;a style="color:#0000ff;">confirm&lt;/a>&lt;/ConfirmOptin> your continued interest in receiving email from us.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstName</GreetingName>
<GreetingString>Greetings!</GreetingString>
<OrganizationName>zoom</OrganizationName>
<OrganizationAddress1>123 west street</OrganizationAddress1>
<OrganizationAddress2 />
<OrganizationAddress3 />
<OrganizationCity>Charlotte</OrganizationCity>
<OrganizationState>NC</OrganizationState>
<OrganizationInternationalState />
<OrganizationCountry>us</OrganizationCountry>
<OrganizationPostalCode>28226</OrganizationPostalCode>
<IncludeForwardEmail>NO</IncludeForwardEmail>
<ForwardEmailLinkText />
<IncludeSubscribeLink>NO</IncludeSubscribeLink>
<SubscribeLinkText />
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>&lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd">&lt;head>&lt;/head>&lt;body>&lt;center>hello world&lt;/center>&lt;/body>&lt;/html></EmailContent>
<EmailTextContent><Text>sdfjsadf</Text></EmailTextContent>
<StyleSheet />
- <ContactLists>
- <ContactList id="http://api.constantcontact.com/ws/customers/custname/lists/13">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/lists/13" rel="self" />
</ContactList>
</ContactLists>
- <FromEmail>
- <Email id="http://api.constantcontact.com/ws/customers/custname/settings/emailaddresses/1">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/1" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</FromEmail>
- <ReplyToEmail>
- <Email id="http://api.constantcontact.com/ws/customers/custname/settings/emailaddresses/1">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/1" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</ReplyToEmail>
</Campaign>
</content>
- <source>
<id>http://api.constantcontact.com/ws/customers/custname/campaigns</id>
<title type="text">Campaigns for customer: custname</title>
<link href="campaigns" />
<link href="campaigns" rel="self" />
- <author>
<name>custname</name>
</author>
<updated>2011-11-30T10:53:26:110Z</updated>
</source>
</entry>

Highlighted
Moderator

Re: Bad Request 400 Error

The first problem I ran into was with the <EmailTextContent> node which is not encoded, I received the following error when running it without that encoded:

 

HTTP/1.1 400 Bad Request

Error 400: Error: Line 30: cvc-type.3.1.2: Element 'EmailTextContent' is a simple type, so it must have no element information item [children].

 

Once I corrected that error, I was able to create the campaign without any problem.  Since you mentioned you are using C# to do the code, I can help you out will pulling the full error message from any error exception.  You'll simply need to put your HttpWebRequest code into a try{} block and then add the following catch statement and code:

 

catch (WebException ex)
{
    StreamReader reader = newStreamReader(ex.Response.GetResponseStream());   
    String responseBody = reader.ReadToEnd();

    HttpStatusCode responseCode = response.StatusCode;
    // Do something with these values that show the error message
}

 

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: Bad Request 400 Error

Well, I am definitely making progress :smileyhappy:

 

That WebException catch is going to be a HUGE help! Thanks for that!

The next error I got was about the Error 400: Not verified Email address for reply-to email address

 

So I have changed that, and got to the next error, where I am stuck again.

Error 400: Invalid Content

 

Any idea what that could be referring to?

Here is the latest XML with my new changes:

 

 

 

 

<?xml version="1.0" encoding="UTF-8" ?>
- <entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/custname/campaigns" rel="edit" />
<id>http://api.constantcontact.com/ws/customers/custname/campaigns</id>
<title type="text">MBOC Last Visit</title>
<updated>2011-11-30T12:15:01:812Z</updated>
- <author>
<name>custname</name>
</author>
- <content type="application/vnd.ctct+xml">
- <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/custname/campaigns">
<Name>MBOC_LastVisit1201_11/30/2011</Name>
<Status>Draft</Status>
<Date>2011-11-30T12:15:01:812Z</Date>
<Subject>We Miss You</Subject>
<FromName>custname</FromName>
<ViewAsWebpage>NO</ViewAsWebpage>
<ViewAsWebpageLinkText />
<ViewAsWebpageText />
<PermissionReminder>NO</PermissionReminder>
<PermissionReminderText>You're receiving this email because of your relationship with Constant Contact. Please &lt;ConfirmOptin&gt;&lt;a style="color:#0000ff;"&gt;confirm&lt;/a&gt;&lt;/ConfirmOptin&gt; your continued interest in receiving email from us.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstName</GreetingName>
<GreetingString>Greetings!</GreetingString>
<OrganizationName>zoom</OrganizationName>
<OrganizationAddress1>123 west street</OrganizationAddress1>
<OrganizationAddress2 />
<OrganizationAddress3 />
<OrganizationCity>Charlotte</OrganizationCity>
<OrganizationState>NC</OrganizationState>
<OrganizationInternationalState />
<OrganizationCountry>us</OrganizationCountry>
<OrganizationPostalCode>28226</OrganizationPostalCode>
<IncludeForwardEmail>NO</IncludeForwardEmail>
<ForwardEmailLinkText />
<IncludeSubscribeLink>NO</IncludeSubscribeLink>
<SubscribeLinkText />
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>&lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd"&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;center&gt;hello world&lt;/center&gt;&lt;/body&gt;&lt;/html&gt;</EmailContent>
<EmailTextContent>&lt;Text&gt;sdfjsadf&lt;/Text&gt;</EmailTextContent>
<StyleSheet />
- <ContactLists>
- <ContactList id="http://api.constantcontact.com/ws/customers/custname/lists/13">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/lists/13" rel="self" />
</ContactList>
</ContactLists>
- <FromEmail>
- <Email id="http://api.constantcontact.com/ws/customers/custname/settings/emailaddresses/4">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/4" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</FromEmail>
- <ReplyToEmail>
- <Email id="http://api.constantcontact.com/ws/customers/custname/settings/emailaddresses/4">
<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/custname/settings/emailaddresses/4" rel="self" />
</Email>
<EmailAddress>mvanwye@custname.com</EmailAddress>
</ReplyToEmail>
</Campaign>
</content>
- <source>
<id>http://api.constantcontact.com/ws/customers/custname/campaigns</id>
<title type="text">Campaigns for customer: custname</title>
<link href="campaigns" />
<link href="campaigns" rel="self" />
- <author>
<name>custname</name>
</author>
<updated>2011-11-30T12:15:01:812Z</updated>
</source>
</entry>

Highlighted
Moderator

Re: Bad Request 400 Error

This is very confusing here on my end as I can use your XML with only a slight modification to reflect my account and this works perfectly with the content as it is.  Is it possible for you to try to replicate in the RESTClient and see if you get the same 400 error there?  If you don't, the odds are that the problem is in the C# code.  If you do, then you can save the request that gets the error and send it to us via email (webservices@constantcontact.com) and we can look at your exact request. 

Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

Highlighted
Occasional Participant

Re: Bad Request 400 Error

Ok, I got it. I hope this helps someone else in the future :)

 

As I said, I am developing in c#, and using VisualStudio. So when I was getting the XML to send to you, I was taking the string that contained my XML, and rendering it in the XML view.

However, you got me thinking about c# being the issue, and that made me think to check the actual text of the XML that I am sending. 

In the text, the "<" looked like this: "&amp;lt;" or seomthing like that.

 

So it was something being "double encoded" or something. So I was able to fix that, and it went through.

 

Thanks so much for the help today - really appreciate it!

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