Failed with 400 Bad Request

Highlighted
Occasional Participant

Failed with 400 Bad Request

I need some help, i want to create a Campaign with the following XML and the WS returns 400 error, what im doing wrong?


<?xml version='1.0' encoding='UTF-8'?>

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

    <title type=\"text\"> </title>

    <updated>2010-12-06T10:22:03Z</updated>

    <author></author>

    <id>data:,none</id>

    <summary type=\"text\">Campaign</summary>

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

      <Campaign xmlns=\"http://ws.constantcontact.com/ns/1.0/\">

        <OrganizationPostalCode>64108</OrganizationPostalCode>

        <IncludeForwardEmail>NO</IncludeForwardEmail>

        <Status>DRAFT</Status>

        <EmailContent>Test campaign</EmailContent>

        <OrganizationState>KS</OrganizationState>

        <GreetingString>Greetings!</GreetingString>

        <Subject>Test campaign</Subject>

        <OrganizationInternationalState></OrganizationInternationalState>

        <Name>Test campaign</Name>

        <EmailContentFormat>HTML</EmailContentFormat>

        <PermissionReminder>YES</PermissionReminder>

        <FromName>juan.colacelli</FromName>

        <StyleSheet></StyleSheet>

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

        <ViewAsWebpage>NO</ViewAsWebpage>

        <GreetingName>FirstName</GreetingName>

        <OrganizationCountry>US</OrganizationCountry>

        <OrganizationAddress1>123 Main</OrganizationAddress1>

        <OrganizationAddress2></OrganizationAddress2>

        <IncludeSubscribeLink>NO</IncludeSubscribeLink>

        <SubscribeLinkText></SubscribeLinkText>

        <GreetingSalutation>Dear</GreetingSalutation>

        <OrganizationAddress3></OrganizationAddress3>

        <EmailTextContent>&lt;Text&gt;Test campaign&lt;/Text&gt;</EmailTextContent>

        <OrganizationCity>Kansas City</OrganizationCity>

        <OrganizationName>juan.colacelli</OrganizationName>

        <ForwardEmailLinkText></ForwardEmailLinkText>

        <ReplyToEmail><Email id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1\"/></ReplyToEmail>

        <FromEmail><Email id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1\"/></FromEmail>

        <ContactLists><ContactList id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/lists/1\"/></ContactLists>

      </Campaign>

    </content>

  </entry>

5 REPLIES 5
Highlighted
Occasional Advisor

Campaign Creation

Hello,


Because we use the Atom specification for XML, there are several elements that are required even though they are not used by the server and are replaced upon a successful contact creation.  These elements are <id>, <title>, <author>, and <updated> elements. The <title> and <author> elements may be empty. The <id> must contain a URI, but since the value is not used by the server, any URI will work. The server does not check for uniqueness when creating a contact because a new unique ID will be created anyway. The <updated> element must contain a date or date/time value, but again the value is not used by the server.


Below is your data reformatted to a working campaign creation format. I would suggest using this as a template for future campaigns and changing the content as needed.


<?xml version='1.0' encoding='UTF-8'?>

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

    <link href="/ws/customers/juan.colacelli/campaigns" rel="edit" />

    <id>http://api.constantcontact.com/ws/customers/juan.colacelli/campaigns</id>

    <title type="text">API Test Email</title>

    <updated>2009-10-19T18:34:53.105Z</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/juan.colacelli/campaigns/1100546096289">

        <Name>Test campaign</Name>

        <Status>DRAFT</Status>

        <Subject>Test campaign</Subject>

        <FromName>juan.colacelli</FromName>

        <ViewAsWebpage>NO</ViewAsWebpage>

        <ViewAsWebpageLinkText></ViewAsWebpageLinkText>

        <ViewAsWebpageText></ViewAsWebpageText>

        <PermissionReminder>YES</PermissionReminder>

        <PermissionReminderText></PermissionReminderText>

        <GreetingSalutation>Dear</GreetingSalutation>

        <GreetingName>FirstName</GreetingName>

        <GreetingString>Greetings!</GreetingString>

        <OrganizationName>juan.colacelli</OrganizationName>

        <OrganizationAddress1>123 Main</OrganizationAddress1>

        <OrganizationAddress2></OrganizationAddress2>

        <OrganizationAddress3></OrganizationAddress3>

        <OrganizationCity>Kansas City</OrganizationCity>

        <OrganizationState>KS</OrganizationState>

        <OrganizationInternationalState></OrganizationInternationalState>

        <OrganizationCountry>US</OrganizationCountry>

        <OrganizationPostalCode>64108</OrganizationPostalCode>

        <IncludeForwardEmail>NO</IncludeForwardEmail>

        <ForwardEmailLinkText></ForwardEmailLinkText>

        <IncludeSubscribeLink>NO</IncludeSubscribeLink>

        <SubscribeLinkText></SubscribeLinkText>

        <EmailContentFormat>HTML</EmailContentFormat>

        <EmailContent>Test campaign</EmailContent>

        <EmailTextContent>&lt;Text&gt;Test campaign&lt;/Text&gt;</EmailTextContent>

        <StyleSheet></StyleSheet>

        <ContactLists>

        <ContactList id="http://api.constantcontact.com/ws/customers/juan.colacelli/lists/1">

          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/juan.colacelli/lists/1" rel="self" />

        </ContactList>

        </ContactLists>

        <FromEmail>

        <Email id="http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1">

          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/juan.colacelli/settings/emailaddresses/1"

          rel="self" />

        </Email>

        <EmailAddress>juan.colacelli@koombea.com</EmailAddress>

      </FromEmail>

      <ReplyToEmail>

        <Email id="http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1">

          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/juan.colacelli/settings/emailaddresses/1"

          rel="self" />

        </Email>

        <EmailAddress>juan.colacelli@koombea.com</EmailAddress>

      </ReplyToEmail>

      </Campaign>

    </content>

      <source>

    <id>http://api.constantcontact.com/ws/customers/juan.colacelli/campaigns</id>

    <title type="text">Campaigns for customer: juan.colacelli</title>

    <link href="campaigns" />

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

    <author>

      <name>juan.colacelli</name>

    </author>

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

  </source>

  </entry>

Andrew T

Support Engineer, Constant Contact

Highlighted
Occasional Participant

Failed with 415 Unsupported Media Type

Now it throw this error "Failed with 415 Unsupported Media Type".


<?xml version='1.0' encoding='UTF-8'?>

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

  <title type=\"text\">Test campaign</title>

  <updated>2010-12-06T16:44:17Z</updated>

  <author>juan.colacelli</author>

  <id>http://api.constantcontact.com/ws/customers/juan.colacelli/campaigns</id>

  <summary type=\"text\">Campaign</summary>

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

  <Campaign xmlns=\"http://ws.constantcontact.com/ns/1.0/\">

    <OrganizationPostalCode>64108</OrganizationPostalCode>

    <IncludeForwardEmail>NO</IncludeForwardEmail>

    <Status>DRAFT</Status>

    <EmailContent>Test campaign</EmailContent>

    <OrganizationState>KS</OrganizationState>

    <GreetingString>Greetings!</GreetingString>

    <Subject>Test campaign</Subject>

    <OrganizationInternationalState></OrganizationInternationalState>

    <Name>Test campaign</Name>

    <EmailContentFormat>HTML</EmailContentFormat>

    <PermissionReminder>YES</PermissionReminder>

    <FromName>juan.colacelli</FromName>

    <StyleSheet></StyleSheet>

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

    <ViewAsWebpage>NO</ViewAsWebpage>

    <GreetingName>FirstName</GreetingName>

    <OrganizationCountry>US</OrganizationCountry>

    <OrganizationAddress1>123 Main</OrganizationAddress1>

    <OrganizationAddress2></OrganizationAddress2>

    <IncludeSubscribeLink>NO</IncludeSubscribeLink>

    <SubscribeLinkText></SubscribeLinkText>

    <GreetingSalutation>Dear</GreetingSalutation>

    <OrganizationAddress3></OrganizationAddress3>

    <EmailTextContent>&lt;Text&gt;Test campaign&lt;/Text&gt;</EmailTextContent>

    <OrganizationCity>Kansas City</OrganizationCity>

    <OrganizationName>juan.colacelli</OrganizationName>

    <ForwardEmailLinkText></ForwardEmailLinkText>

    <ReplyToEmail><Email id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1\"/></ReplyToEmail>

    <FromEmail><Email id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1\"/></FromEmail>

    <ContactLists><ContactList id=\"http://api.constantcontact.com/ws/customers/juan.colacelli/lists/1\"/></ContactLists></Campaign>

  </content>

</entry>

Highlighted
CTCT Employee

415 error

Hello,



I tried Andrew's code on my end and I was able to get it to post to my account. Usually when you get a 415 error it is because you are trying to do a POST/GET/PUT/DELETE to a URI that does not allow it, or the header for Content-Type is not correct.



What URI are you posting this to? Also, are you using the header: Content-Type:application/atom+xml? If you are, can you please send your code to the webservices support team so that we can check out what is going on?



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Participant

Im consulting at

Im consulting at https://api.constantcontact.com/ws/customers/juan.colacelli/campaigns with the following XML and the same error (Failed with 415 Unsupported Media Type).


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

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

          <title type="text">Test campaign</title>

          <updated>2010-12-07T12:32:25Z</updated>

          <author>

            <name>juan.colacelli</name>

          </author>

          <id>http://api.constantcontact.com/ws/customers/juan.colacelli/campaigns</id>

          <summary type="text">Campaign</summary>

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

            <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/">

              <OrganizationPostalCode>64108</OrganizationPostalCode>

              <IncludeForwardEmail>NO</IncludeForwardEmail>

              <Status>DRAFT</Status>

              <EmailContent>Test campaign</EmailContent>

              <OrganizationState>KS</OrganizationState>

              <GreetingString>Greetings!</GreetingString>

              <Subject>Test campaign</Subject>

              <OrganizationInternationalState></OrganizationInternationalState>

              <Name>Test campaign</Name>

              <EmailContentFormat>HTML</EmailContentFormat>

              <PermissionReminder>YES</PermissionReminder>

              <FromName>juan.colacelli</FromName>

              <StyleSheet></StyleSheet>

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

              <ViewAsWebpage>NO</ViewAsWebpage>

              <GreetingName>FirstName</GreetingName>

              <OrganizationCountry>US</OrganizationCountry>

              <OrganizationAddress1>123 Main</OrganizationAddress1>

              <OrganizationAddress2></OrganizationAddress2>

              <IncludeSubscribeLink>NO</IncludeSubscribeLink>

              <SubscribeLinkText></SubscribeLinkText>

              <GreetingSalutation>Dear</GreetingSalutation>

              <OrganizationAddress3></OrganizationAddress3>

              <EmailTextContent>&lt;Text&gt;Test campaign&lt;/Text&gt;</EmailTextContent>

              <OrganizationCity>Kansas City</OrganizationCity>

              <OrganizationName>juan.colacelli</OrganizationName>

              <ForwardEmailLinkText></ForwardEmailLinkText>

              <ReplyToEmail><Email id="http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1"/></ReplyToEmail>

              <FromEmail><Email id="http://api.constantcontact.com/ws/customers/juan.colacelli/settings/emailaddresses/1"/></FromEmail>

              <ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/juan.colacelli/lists/1"/></ContactLists></Campaign>

          </content>

        </entry>

Highlighted
Occasional Advisor

Unsupported Media Type

Hello,


As the XML is valid, this leads me to believe that the method you are using to POST your data did not set your Content-Type correctly.


Please ensure that the Content-Type of your HTTP POST is set to "application/atom+xml"

Andrew T

Support Engineer, Constant Contact

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured