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?
Solved! Go to Solution.
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.
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.
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 <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>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><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd"><head></head><body><center>hello world</center></body></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>
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}
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 <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>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><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd"><head></head><body><center>hello world</center></body></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/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>
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.
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: "&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!
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article