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
Occasional Visitor

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

Hi,

While creating a new campaign using the .Net wrapper classes i am getting "The remote server returned an error: (400) Bad Request.".

Refer the following xml.

<?xml version='1.0' encoding='UTF-8'?><entry xmlns="http://www.w3.org/2005/Atom"><link href="/ws/customers/username_redaccted/campaigns" rel="edit" /><id>http://api.constantcontact.com/ws/customers/username_redaccted/campaigns</id><title type="text">New Campaign634964559446005046</title><updated>2013-02-14T16:25:47.2686572+05:30</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/username_redaccted/campaigns/0000000000000" ><Name>New Campaign634964559446005046</Name><Status>Draft</Status><Date>0001-01-01T00:00:00.0000000</Date><Subject>New Campaign</Subject><FromName>whoami1091</FromName><ViewAsWebpage>NO</ViewAsWebpage><ViewAsWebpageLinkText>Click Here</ViewAsWebpageLinkText><ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText><PermissionReminder>NO</PermissionReminder><PermissionReminderText>You're receiving this email because of your relationship with extentia.kmt. Please confirm your continued interest in receiving email from us.</PermissionReminderText><GreetingSalutation></GreetingSalutation><GreetingString></GreetingString><OrganizationName></OrganizationName><OrganizationAddress1></OrganizationAddress1><OrganizationAddress2></OrganizationAddress2><OrganizationAddress3></OrganizationAddress3><OrganizationCity></OrganizationCity><OrganizationState></OrganizationState><OrganizationInternationalState></OrganizationInternationalState><OrganizationCountry></OrganizationCountry><OrganizationPostalCode></OrganizationPostalCode><IncludeForwardEmail>NO</IncludeForwardEmail><ForwardEmailLinkText>Forward</ForwardEmailLinkText><IncludeSubscribeLink>NO</IncludeSubscribeLink><SubscribeLinkText>Subscribe</SubscribeLinkText><GreetingName>FirstName</GreetingName><EmailContentFormat>HTML</EmailContentFormat><EmailContent>&lt;p&gt;Hello&lt;/p&gt;</EmailContent><EmailTextContent>&lt;p&gt;Hello&lt;/p&gt;</EmailTextContent><StyleSheet></StyleSheet><ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/username_redaccted/lists/1"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username_redaccted/lists/1" rel="self" /></ContactList></ContactLists><FromEmail><Email id="http://api.constantcontact.com/ws/customers/username_redaccted/settings/emailaddresses/0"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username_redaccted/settings/emailaddresses/0" rel="self" /></Email><EmailAddress>username_redaccted</EmailAddress></FromEmail><ReplyToEmail><Email id="http://api.constantcontact.com/ws/customers/username_redaccted/settings/emailaddresses/0"><link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username_redaccted/settings/emailaddresses/0" rel="self" /></Email><EmailAddress></EmailAddress></ReplyToEmail></Campaign></content><source><id>http://api.constantcontact.com/ws/customers/username_redaccted/campaigns</id><title type="text">Campaigns for customer: username_redaccted</title><link href="campaigns" /><link href="campaigns" rel="self" /><author><name>username_redaccted</name></author><updated>2013-02-14T16:25:47.2716573+05:30</updated></source></entry>

Refer the below code:

ConstantContactBO.Entities.EmailCampaign newCampaign = new ConstantContactBO.Entities.EmailCampaign();
newCampaign.ContactLists = new List<ContactList>(list);
newCampaign.Name = "New Campaign" + DateTime.Now.Ticks;
newCampaign.FromEmail = "username_redaccted";
newCampaign.FromName = "whoami1091";
newCampaign.Subject = "New Campaign";
newCampaign.Content = System.Web.HttpUtility.HtmlEncode(textBox1.Text);
newCampaign.TextContent = newCampaign.Content;
newCampaign.IncludeSubscribeLink = false;
newCampaign.SubscribeLinkText = "Subscribe";
newCampaign.IncludeForwardEmail = false;
newCampaign.ForwardEmailLinkText = "Forward";
newCampaign.ViewAsWebpage = false;
newCampaign.ViewAsWebpageLinkText = "Click Here";
newCampaign.ViewAsWebpageText = "Having trouble viewing this email?";
newCampaign.EmailContentFormat = "HTML";
newCampaign.PermissionReminder = false;
newCampaign.PermissionReminderText = "You're receiving this email because of your relationship with extentia.kmt. Please confirm your continued interest in receiving email from us.";
newCampaign.GreetingName = "FirstName";
newCampaign.CampaignType = CampaignType.CUSTOM;
Utility.CreateNewEmailCampaign(authdata, newCampaign);

1 REPLY 1
Highlighted
Employee

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

Hi,

 

You're missing a couple of necessary items, like from and reply to email address, in your code, and sending some mixed messages, like having the permission reminder and forward email nodes set to false (NO in the XML) and then providing text for their values.  Here is some code that I know is free of inconsistencies and has all of the required fileds if you want to use it as a starting point (or just compare to yours to figure out the issues).

 

ConstantContactBO.Entities.EmailCampaign emailCampaign = new ConstantContactBO.Entities.EmailCampaign();
emailCampaign.Name = string.Format("API Test - Date ");
emailCampaign.GreetingName = "FirstName";
emailCampaign.CampaignType = ConstantContactBO.CampaignType.CUSTOM;
emailCampaign.Subject = "Subject line text";
emailCampaign.FromName = "Account Organization Name";
emailCampaign.FromEmailID = 1;
emailCampaign.FromEmail = "verifiedemail@example.com";
emailCampaign.ReplyToEmailID = 1;
emailCampaign.ReplyToEmail = "verifiedemail@example.com";
emailCampaign.EmailContentFormat = "HTML";
emailCampaign.Content = "&lt;html&gt;&lt;body&gt;&lt;p&gt;Hello!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;";
emailCampaign.TextContent = "test";
emailCampaign.ContactLists = new System.Collections.Generic.List<ConstantContactBO.ContactList>();
emailCampaign.ContactLists.Add(new ConstantContactBO.ContactList("1"));
emailCampaign.OrganizationName = "CTCT";
emailCampaign.OrganizationAddress1 = "1 flower st";
emailCampaign.OrganizationCity = "Waltham";
emailCampaign.OrganizationCountry = "US";
emailCampaign.OrganizationPostalCode = "02453";
emailCampaign.OrganizationState = "MA";

emailCampaign = ConstantContactUtility.Utility.CreateNewEmailCampaign(authdata, emailCampaign);

 

 

Best Regards,

Shannon W.

API Support Specialist

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