Reply
DaveBerard
Posts: 1,642
Topics: 7
Kudos: 61
Solutions: 59
Registered: ‎06-19-2008

Re: The ever popular Error 400: The request contains...

In looking at your XML, there two problems that would cause you to get an error message and one was pointed out by Shawn: FromEmail and ReplyToEmail must have a valid ID.  To get the valid IDs of verified addresses in your account you would have to use the get request for the settings email addresses, pick the one you want to use and set the ID to that email address.  If you do not set a valid email address for the FromEmail and ReplyToEmail, you will correctly receive a 400 error through the API.

 

Second problem, the content you are putting in for EmailContent and EmailTextContent must be HTML encoded before assigning it to Campaign.Content and Campaign.TextContent.  You can do that in .NET by using the WebUtility.HtmlEncode(String) method.  Not encoding the content of these nodes will cause a 400 or potentially a 500 error depending ont he content of these nodes and can be very difficult to solve by looking at the error messages. 

 

RE the "unclosed tags" you pointed out, they are actually just self closed (notice the /> at the end of each one of those tags).  In XML, just like in HTML, you can end markup nodes that have no value with a self closing /> tag.  These nodes are included still because the XML validation on our side requires them to be present in the markup even though they have no values.  As for your questions on the <Date> node, Campaign id attribute, <updated> node and the rel="edit" attribute for the <link> node, none of these nodes are write nodes.  They are read only and actually set on the server side upon Campaign creation.  They are set to dummy values in the API as the XML validation requires them to be present.

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant
PaulT80
Posts: 4
Registered: ‎01-09-2012

Re: The ever popular Error 400: The request contains...

Thank you for all the help and recomendations. I've attempted to make all the changes recommended though unfortunately I am still getting the same error message back. I've included the text below that is the data that is sent over in the hopes that something will jump out at you all and I can get over this hump. I've also included the c# that I am using to generate the data in case that has something glaring that you can see.

 

Again, thanks for all the help and info with this!

 

 

 

<?xml version='1.0' encoding='UTF-8'?><entry xmlns="http://www.w3.org/2005/Atom"><link href="/ws/customers/pothomas@_________.com/campaigns" rel="edit" /><id>http://api.constantcontact.com/ws/customers/pothomas@_________.com/campaigns</id><title type="text">test campaign</title><updated>2012-01-17T21:59:40.6980369-05:00</updated><author><name>Constant Contact</name></author><content type="application/vnd.ctct+xml"><Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/pothomas@_________.com/campaigns/0000000000000" ><Name>test campaign</Name><Status>Draft</Status><Date>2012-01-17T21:58:41.6945088-05:00</Date><Subject>test subject</Subject><FromName>__________</FromName><ViewAsWebpage>NO</ViewAsWebpage><ViewAsWebpageLinkText></ViewAsWebpageLinkText><ViewAsWebpageText></ViewAsWebpageText><PermissionReminder>YES</PermissionReminder><PermissionReminderText>You're receiving this email because of your relationship with ctct. 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><GreetingString>Greetings!</GreetingString><OrganizationName>LifeSaver</OrganizationName><OrganizationAddress1>123 Main</OrganizationAddress1><OrganizationAddress2></OrganizationAddress2><OrganizationAddress3></OrganizationAddress3><OrganizationCity>Anytown</OrganizationCity><OrganizationState>GA</OrganizationState><OrganizationInternationalState></OrganizationInternationalState><OrganizationCountry>US</OrganizationCountry><OrganizationPostalCode></OrganizationPostalCode><IncludeForwardEmail>NO</IncludeForwardEmail><ForwardEmailLinkText></ForwardEmailLinkText><IncludeSubscribeLink>NO</IncludeSubscribeLink><SubscribeLinkText></SubscribeLinkText><GreetingName>FirstName</GreetingName><EmailContentFormat>HTML</EmailContentFormat><EmailContent>&lt;html&gt;&lt;body&gt;test&lt;/body&gt;&lt;/html&gt;</EmailContent><EmailTextContent>&lt;Text&gt;This is the text version.&lt;/Text&gt;</EmailTextContent><StyleSheet></StyleSheet><ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/pothomas@_________.com/lists/2"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/pothomas@_________.com/lists/2" rel="self" /></ContactList></ContactLists><FromEmail><Email id="http://api.constantcontact.com/ws/customers/pothomas@_________.com/settings/emailaddresses/0"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/pothomas@_________.com/settings/emailaddresses/0" rel="self" /></Email><EmailAddress><?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom">   <link href="/ws/customers/pothomas%40_________.com/settings/emailaddresses/1" rel="edit"></link>   <id>http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses/1</id>   <title type="text">pothomas@_________.com</title>   <updated>2003-07-28T18:30:37.443Z</updated>   <author>     <name>Constant Contact</name>   </author>   <content type="application/vnd.ctct+xml">     <Email xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses/1">       <EmailAddress>pothomas@_________.com</EmailAddress>       <Status>Verified</Status>       <VerifiedTime>2003-07-28T18:30:37.443Z</VerifiedTime>     </Email>   </content>   <source>     <id>http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses</id>     <title type="text"></title>     <link href="emailaddresses"></link>     <link href="emailaddresses" rel="self"></link>     <author>       <name>pothomas@_________.com</name>     </author>     <updated>2012-01-18T02:59:11.272Z</updated>   </source> </entry></EmailAddress></FromEmail><ReplyToEmail><Email id="http://api.constantcontact.com/ws/customers/pothomas@_________.com/settings/emailaddresses/0"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/pothomas@_________.com/settings/emailaddresses/0" rel="self" /></Email><EmailAddress><?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom">   <link href="/ws/customers/pothomas%40_________.com/settings/emailaddresses/1" rel="edit"></link>   <id>http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses/1</id>   <title type="text">pothomas@_________.com</title>   <updated>2003-07-28T18:30:37.443Z</updated>   <author>     <name>Constant Contact</name>   </author>   <content type="application/vnd.ctct+xml">     <Email xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses/1">       <EmailAddress>pothomas@_________.com</EmailAddress>       <Status>Verified</Status>       <VerifiedTime>2003-07-28T18:30:37.443Z</VerifiedTime>     </Email>   </content>   <source>     <id>http://api.constantcontact.com/ws/customers/pothomas%40_________.com/settings/emailaddresses</id>     <title type="text"></title>     <link href="emailaddresses"></link>     <link href="emailaddresses" rel="self"></link>     <author>       <name>pothomas@_________.com</name>     </author>     <updated>2012-01-18T02:59:11.994Z</updated>   </source> </entry></EmailAddress></ReplyToEmail></Campaign></content><source><id>http://api.constantcontact.com/ws/customers/pothomas@_________.com/campaigns</id><title type="text">Campaigns for customer: pothomas@_________.com</title><link href="campaigns" /><link href="campaigns" rel="self" /><author><name>pothomas@_________.com</name></author><updated>2012-01-17T21:59:40.7292370-05:00</updated></source></entry>

 

 

 

     ConstantContactBO.Entities.EmailCampaign campaign = new ConstantContactBO.Entities.EmailCampaign();             campaign.Name = "test campaign";            

campaign.State = CampaignState.Draft;           

  campaign.Date = System.DateTime.Now;           

  campaign.Subject = "test subject";            

 campaign.FromName = "_________";            

campaign.ViewAsWebpage = false;            

 campaign.ViewAsWebpageLinkText = "";            

 campaign.ViewAsWebpageText = "";            

 campaign.PermissionReminder = true;           

  campaign.PermissionReminderText = "You're receiving this email because of your relationship with ctct. Please &lt;ConfirmOptin>&lt;a style=\"color:#0000ff;\">confirm&lt;/a>&lt;/ConfirmOptin> your continued interest in receiving email from us.";           
  campaign.GreetingSalutation = "Dear";            

campaign.GreetingName = "FirstName";           

  campaign.GreetingString = "Greetings!";         

    campaign.OrganizationName = "_________";            

 campaign.OrganizationAddress1 = "123 Main";            

campaign.OrganizationAddress2 = "";       

      campaign.OrganizationAddress3 = "";     

        campaign.OrganizationCity = "Anytown";
            campaign.OrganizationState = "GA";   

          campaign.OrganizationInternationalState = "";         

    campaign.OrganizationCountry = "US";           

  campaign.IncludeForwardEmail = false;            

 campaign.ForwardEmailLinkText = "";            

 campaign.IncludeSubscribeLink = false;            

 campaign.SubscribeLinkText = "";

            campaign.EmailContentFormat = "HTML";            

 campaign.Content = System.Net.WebUtility.HtmlEncode("<html><body>test</body></html>");             campaign.TextContent = System.Net.WebUtility.HtmlEncode("<Text>This is the text version.</Text>");             campaign.StyleSheet = "";

            string t = "";            

 ContactList cList = Utility.GetContactListCollection(authdata, out t)[0];           

  campaign.ContactLists = new List<ContactList>(1);           

  campaign.ContactLists.Add(cList);           

  campaign.FromEmail = Utility.httpGet(authdata, "https://api.constantcontact.com/ws/customers/" + authdata.Username + "/settings/emailaddresses/1");            

 campaign.ReplyToEmail = Utility.httpGet(authdata, "https://api.constantcontact.com/ws/customers/" + authdata.Username + "/settings/emailaddresses/1");      

       campaign.CampaignType = CampaignType.CUSTOM;     
        Utility.CreateNewEmailCampaign(authdata, campaign);