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.

Creating Campaigns 400 error.

Highlighted
Advisor

Creating Campaigns 400 error.

No idea what is causing this. Here is my code.

 

string

XMLData = "";

                XMLData +=

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

                XMLData +=

"<entry xmlns=\"http://www.w3.org/2005/Atom\">";

                XMLData +=

"<link href=\"/ws/customers/smimarketing/campaigns\" rel=\"edit\" />";

                XMLData +=

"<id>http://api.constantcontact.com/ws/customers/smimarketing/campaigns</id>";

                XMLData +=

"<title type=\"text\">Test Email</title>";

                XMLData +=

"<updated>2011-10-30T19:34:53.105Z</updated>";

                XMLData +=

"<author>";

                XMLData +=

"<name>Constant Contact</name>";

                XMLData +=

"</author>";

                XMLData +=

"<content type=\"application/vnd.ctct+xml\">";

                XMLData +=

"<Campaign xmlns=\"http://ws.constantcontact.com/ns/1.0/\" id=\"http://api.constantcontact.com/ws/customers/smimarketing/campaigns/3\">";

               

                XMLData +=

"<Name>API Test Email</Name>";

                XMLData +=

"<Status>Draft</Status>";

                XMLData +=

"<Date>2009-10-19T18:34:53.105Z</Date>";

                XMLData +=

"<Subject>Test Email</Subject>";

                XMLData +=

"<FromName>smi@strategicmarketing.com</FromName>";

                XMLData +=

"<ViewAsWebpage>NO</ViewAsWebpage>";

                XMLData +=

"<ViewAsWebpageLinkText></ViewAsWebpageLinkText>";

                XMLData +=

"<ViewAsWebpageText></ViewAsWebpageText>";

                XMLData +=

"<PermissionReminder>NO</PermissionReminder>";

                XMLData +=

"<PermissionReminderText></PermissionReminderText>";

                XMLData +=

"<GreetingSalutation>Dear</GreetingSalutation>";

                XMLData +=

"<GreetingName>FirstName</GreetingName>";

                XMLData +=

"<GreetingString>Greetings!</GreetingString>";

                XMLData +=

"<OrganizationName>ctct</OrganizationName>";

                XMLData +=

"<OrganizationAddress1>123 wsw st</OrganizationAddress1>";

                XMLData +=

"<OrganizationAddress2></OrganizationAddress2>";

                XMLData +=

"<OrganizationAddress3></OrganizationAddress3>";

                XMLData +=

"<OrganizationCity>Ashland</OrganizationCity>";

                XMLData +=

"<OrganizationState>MA</OrganizationState>";

                XMLData +=

"<OrganizationInternationalState></OrganizationInternationalState>";

                XMLData +=

"<OrganizationCountry>us</OrganizationCountry>";

                XMLData +=

"OrganizationPostalCode>32423</OrganizationPostalCode>";

                XMLData +=

"<IncludeForwardEmail>NO</IncludeForwardEmail>";

                XMLData +=

"<ForwardEmailLinkText></ForwardEmailLinkText>";

                XMLData +=

"<IncludeSubscribeLink>NO</IncludeSubscribeLink>";

                XMLData +=

"<SubscribeLinkText></SubscribeLinkText>";

                XMLData +=

"<EmailContentFormat>HTML</EmailContentFormat>";

                XMLData +=

"<EmailContent>&lt;html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:cctd=\"http://www.constantcontact.com/cctd\">&lt;body>&lt;CopyRight>Copyright (c) 1996-2009 Constant Contact. All rights reserved.  Except as permitted under aseparatewritten agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on anyConstant Contact site,including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, ordistributed without theprior written permission of Constant Contact.  For inquiries regarding reproduction or distribution of any ConstantContact material, pleasecontact joesflowers@example.com.&lt;/CopyRight>&lt;OpenTracking/>&lt;!--  Do NOT delete previous line if you want to get statistics on the number of opened emails -->&lt;CustomBlock name=\"letter.intro\" title=\"Personalization\">    &lt;Greeting/>&lt;/CustomBlock>&lt;/body>&lt;/html></EmailContent>";

                XMLData +=

"<EmailTextContent>&lt;Text>This is the text version.&lt;/Text></EmailTextContent>";

                XMLData +=

"<StyleSheet></StyleSheet>";

                XMLData +=

"<ContactLists>";

                XMLData +=

"<ContactList id=\"http://api.constantcontact.com/ws/customers/smimarketing/lists/1\"><link xmlns=\"http://www.w3.org/2005/Atom\" href=\"/ws/customers/smimarketing/lists/1\" rel=\"self\"/></ContactList>";

                XMLData +=

"</ContactLists>";

                XMLData +=

"<FromEmail>";

                XMLData +=

"<Email id=\"http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/1\"><link xmlns=\"http://www.w3.org/2005/Atom\" href=\"/ws/customers/smimarketing/settings/emailaddresses/1\" rel=\"self\"/></Email>";

                XMLData +=

"<EmailAddress>me@me.com</EmailAddress>";

                XMLData +=

"</FromEmail>";

                XMLData +=

"<ReplyToEmail>";

                XMLData +=

"<Email id=\"http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/1\"><link xmlns=\"http://www.w3.org/2005/Atom\" href=\"/ws/customers/smimarketing/settings/emailaddresses/1\" rel=\"self\" /></Email>";

                XMLData +=

"<EmailAddress>me@me.com</EmailAddress>";

                XMLData +=

"</ReplyToEmail>";

                XMLData +=

"</Campaign>";

                XMLData +=

"</content>";

                XMLData +=

"<source>";

                XMLData +=

"<id>http://api.constantcontact.com/ws/customers/smimarketing/campaigns</id>";

                XMLData +=

"<title type=\"text\">Campaigns for customer: smimarketing</title>";

                XMLData +=

"<link href=\"campaigns\" />";

                XMLData +=

"<link href=\"campaigns\" rel=\"self\" />";

                XMLData +=

"<author>";

                XMLData +=

"<name>smimarketing</name>";

                XMLData +=

"</author>";

                XMLData +=

"<updated>2009-10-19T19:36:12.622Z</updated>";

                XMLData +=

"</source>";

                XMLData +=

"</entry>";

               

byte[] byteArray = Encoding.UTF8.GetBytes(XMLData);

               

CredentialCache LoginCredentials = newCredentialCache();

               

string ContactURI = String.Format("https://api.constantcontact.com/ws/customers/{0}/{1}", API_USERNAME, API_RESOURCE_CAMPAIGNS);

                LoginCredentials.Add(

newUri(@"https://api.constantcontact.com/ws/customers/smimarketing"), "Basic", newNetworkCredential(API_KEY + @"%" + API_USERNAME, API_PASSWORD));

 

               

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ContactURI);

                request.Credentials = LoginCredentials;

                request.Method =

"POST";

                request.ContentType =

@"application/atom+xml";

                request.ContentLength = byteArray.Length;

               

Stream dataStream = request.GetRequestStream();

                dataStream.Write(byteArray, 0, byteArray.Length);

                dataStream.Close();

               

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

               

string returnString = response.StatusCode.ToString();

15 REPLIES 15
Highlighted
Moderator

Re: Creating Campaigns 400 error.

Couple questions Rachel.  Is this your exact unmodified code?   If so, it is likely that the email address that you're using in the FromEmail and ReplyEmail is not a verified email address in your account (I looked it up and noticed you have two verified addresses, neither of which is me@me.com).  If you obfuscated the email address for posting here, please ignore that point and let me know if that's the case.

 

Did you use a try/catch block to catch the WebException and then use the WebException.Response property to read the full response message?  We send back a full response body that will often times give you the exact cause of the 400 error in the full body.  That could give us guidance on the problem. 

 

We will be able to get back to you later after running your code locally against an account internally and trying to track down there error here, should have more information early this afternoon.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Advisor

Re: Creating Campaigns 400 error.

Whoa thanks Dave.  This was exact :( so I will be looking for these verified email addresses.  Any idea on how i could find those quickly?

 

Highlighted
Moderator

Re: Creating Campaigns 400 error.

All verified email addresses are part of the EmailSettings collectoin.  You can do a GET request against it to pull all the verified addresses and then allow the user to pick from a list of the available addresses for the FromEmail and ReplyEmail.  You can find documentation on that collection here: http://community.constantcontact.com/t5/Documentation/Account-Email-Addresses-Collection/ba-p/25091

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Advisor

Re: Creating Campaigns 400 error.

Ok so I have changed the emails to the correct ones?  I am still getting the error.  I am debugging it and trying to get the WebExcepiton response but i do not know exactly what I am looking for?  Also was I suppose to GET the id's for the 2 verified addresses or just use them in the *********@*******.com form

 

Thanks dave

Highlighted
Moderator

Re: Creating Campaigns 400 error.

You will need to update the entire ReplyEmail and FromEmail XML with the full information that you pulled from the EmailAddress Collection.  When you're catching the WebException error, here is some code you can use to pull the full error response message and see what the exact error message is that we return:

 

           

catch (WebException ex)

{

               StreamReader reader = new StreamReader(ex.Response.GetResponseStream());

               String responseBody = reader.ReadToEnd();

               String responseCode = ((HttpWebResponse)ex.Response).StatusCode;

}

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Advisor

Re: Creating Campaigns 400 error.

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses</id>
  <title type="text"></title>
  <link href="emailaddresses"></link>
  <link href="emailaddresses" rel="self"></link>
  <author>
    <name>smimarketing</name>
  </author>
  <updated>2011-11-01T15:09:48.979Z</updated>
  <entry>
    <link href="/ws/customers/smimarketing/settings/emailaddresses/1" rel="edit"></link>
    <id>http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/1</id>
    <title type="text">rachel@strategicmarketing.com</title>
    <updated>2011-09-13T20:38:09.045Z</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/smimarketing/settings/emailaddresses/1">
        <EmailAddress>rachel@strategicmarketing.com</EmailAddress>
        <Status>Verified</Status>
        <VerifiedTime>2011-09-13T20:38:09.045Z</VerifiedTime>
      </Email>
    </content>
  </entry>
  <entry>
    <link href="/ws/customers/smimarketing/settings/emailaddresses/2" rel="edit"></link>
    <id>http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/2</id>
    <title type="text">tom@strategicmarketing.com</title>
    <updated>2011-09-27T20:03:25.424Z</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/smimarketing/settings/emailaddresses/2">
        <EmailAddress>tom@strategicmarketing.com</EmailAddress>
        <Status>Verified</Status>
        <VerifiedTime>2011-09-27T20:03:25.424Z</VerifiedTime>
      </Email>
    </content>
  </entry>
</feed>

 

 

Using the RESTClient this is what i get.  So i just replace rachel@smimarketing.com and tom@smimarketing.com for the campaign XML... I dont fully understand what you mean by "update the entire ReplyEmail and FromEmail XML with the full information that you pulled."

Highlighted
Moderator

Re: Creating Campaigns 400 error.

If you notice you received multiple <entry> nodes with the response XML that have details on each verified email address.  Here is the code you are correctly using to set the FromEmail, you'll want to pull the information from the XML you just received and use that to correctly populate the related fields.  You'll see that they map up directly with the same named fields and nodes from the XML you posted above. 

 

 XMLData += "<FromEmail>";

XMLData += "<Email id=\"http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/1\"><link xmlns=\"http://www.w3.org/2005/Atom\" href=\"/ws/customers/smimarketing/settings/emailaddresses/1\" rel=\"self\"/></Email>";

XMLData += "<EmailAddress>me@me.com</EmailAddress>";

XMLData += "</FromEmail>";

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Advisor

Re: Creating Campaigns 400 error.

Ok thankyou then.

 

when i get the email node i get it back like this

 

<Email xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/2">
        <EmailAddress>tom@strategicmarketing.com</EmailAddress>
        <Status>Verified</Status>
        <VerifiedTime>2011-09-27T20:03:25.424Z</VerifiedTime>
      </Email>

 

<Email xmlns=\"http://ws.constantcontact.com/ns/1.0/\" id=\"http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/2\"><EmailAddress>tom@strategicmarketing.com</EmailAddress><Status>Verified</Status><VerifiedTime>2011-09-27T20:03:25.424Z</VerifiedTime></Email>";

 

i do not know which one of these is the correct one to use.  But both methods on email 1 and 2 do not work i get this message now using the catch.

 

Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

 

 

Highlighted
Advisor

Re: Creating Campaigns 400 error.

sorry this is the other one i was using

 

XMLData += "<Email id=\"http://api.constantcontact.com/ws/customers/smimarketing/settings/emailaddresses/2\"><link xmlns=\"http://www.w3.org/2005/Atom\" href=\"/ws/customers/smimarketing/settings/emailaddresses/2\" rel=\"self\" /></Email>";

 

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