Getting '400' error while trying to create a campaign using API

Highlighted
Occasional Contributor

Getting '400' error while trying to create a campaign using API

I'm getting a '400' error while trying to create a campaign through API. Little bit of googling suggested that, it should be a problem with XML format.

 

<?xml version="1.0"?> 
<entry xmlns="http://www.w3.org/2005/Atom">
    <link href="/ws/customers/shameerc/campaigns" rel="edit"/>
    <id>http://api.constantcontact.com/ws/customers/shameerc/campaigns</id>
    <title type="text">Test</title>
    <updated>2011-07-25T14:18:18+01: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/shameerc/campaigns/1100546096289">
            <Name>Test</Name>
            <Status>draft</Status>
            <Date>2011-07-25T14:18:18+01:00</Date>
            <Subject>test subject</Subject>
            <FromName>spasyndicate</FromName>
            <ViewAsWebpage></ViewAsWebpage>
            <ViewAsWebpageLinkText></ViewAsWebpageLinkText>
            <ViewAsWebpageText></ViewAsWebpageText>
            <PermissionReminder></PermissionReminder>
            <PermissionReminderText></PermissionReminderText>
            <GreetingSalutation>dfsdfsdf</GreetingSalutation>
            <GreetingName>fsdf</GreetingName>
            <GreetingString>dsfsdfsd</GreetingString>
            <OrganizationName>dsfsdf</OrganizationName>
            <OrganizationAddress1>sdfsdf</OrganizationAddress1>
            <OrganizationAddress2>dsfsdf</OrganizationAddress2>
            <OrganizationAddress3>sdfdsf</OrganizationAddress3>
            <OrganizationCity>fsdf</OrganizationCity>
            <OrganizationState>fsdf</OrganizationState>
            <OrganizationInternationalState>fds</OrganizationInternationalState>
            <OrganizationCountry>fdsf</OrganizationCountry>
            <OrganizationPostalCode>232132</OrganizationPostalCode>
            <IncludeForwardEmail></IncludeForwardEmail>
            <ForwardEmailLinkText>sdfsdf</ForwardEmailLinkText>
            <IncludeSubscribeLink></IncludeSubscribeLink>
            <SubscribeLinkText></SubscribeLinkText>
            <EmailContentFormat>html</EmailContentFormat>
            <EmailContent>fdfsdfsdfsdfsdf</EmailContent>
            <EmailTextContent>dsfsdfsdfsdfsd</EmailTextContent>
            <StyleSheet></StyleSheet>
            <ContactLists/>
            <FromEmail>
                <Email id="http://api.constantcontact.com">
                    <link xmlns="http://www.w3.org/2005/Atom" href="" rel="self"/>
                </Email>
                <EmailAddress/>
            </FromEmail>
            <ReplyToEmail>
                <Email id="http://api.constantcontact.com">
                    <link xmlns="http://www.w3.org/2005/Atom" href="" rel="self"/>
                </Email>
                <EmailAddress/>
            </ReplyToEmail>
        </Campaign>
    </content>
    <source>
        <id>http://api.constantcontact.com/ws/customers/shameerc/campaigns</id>
        <title type="text">Campaigns for customer: shameerc</title>
        <link href="campaigns"/>
        <link href="campaigns" rel="self"/>
        <author>
            <name>shameerc</name>
        </author>
        <updated>2011-07-25T14:18:18+01:00</updated>
    </source>
</entry> 

 

3 REPLIES 3
Highlighted
CTCT Employee

Re: Getting '400' error while trying to create a campaign using API

Hello,

 

I can definitely help you with the 400 errors you are receiving.  I took a look at your XML and I do see a few things that would be causing this.

 

The nodes ViewAsWebPage, PermissionReminder, IncludeSubscribeLink, and IncludeForwardEmail must have something in it, either a yes or no.  If you do not want either then you must choose no for each node.

 

Also, the GreetingName node must be specific as well.  It can either be FirstName, LastName, FirstAndLastName, or none.

 

I also noticed that you do not include a verified From or ReplyTo address.  These must be set correctly, and a valid contact list must be set as well.

 

One other problem is that when submitting the campaign, the EmailContent and EmailTextContent nodes need to be correct.  The EmailContent needs to be correct HTML/XHTML and the Text content needs to be surrounded by text tags.

 

After fixing these issues I was able to post your XML.  Also, please take a look at this documentation that goes further into the requirements of campaign XML.

 

If you have any further questions please let me know.

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Contributor

Re: Getting '400' error while trying to create a campaign using API

Ok thanks, that worked out. But now am getting a '500' error! I used http://api.constantcontact.com/ws/customers/shameerc/campaigns for the Post. The xml is as follows

<?xml version="1.0" encoding="UTF-8"?> 
<entry xmlns="http://www.w3.org/2005/Atom">
    <link href="/ws/customers/shameerc/campaigns" rel="edit"/>
    <id>http://api.constantcontact.com/ws/customers/shameerc/campaigns</id>
    <title type="text">Test</title>
    <updated>2011-07-26T11:08:41+01: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/shameerc/campaigns/1100546096289">
            <Name>Test</Name>
            <Status>draft</Status>
            <Date>2011-07-26T11:08:41+01:00</Date>
            <Subject>test subject</Subject>
            <FromName>spasyndicate</FromName>
            <ViewAsWebpage>No</ViewAsWebpage>
            <ViewAsWebpageLinkText></ViewAsWebpageLinkText>
            <ViewAsWebpageText></ViewAsWebpageText>
            <PermissionReminder>No</PermissionReminder>
            <PermissionReminderText></PermissionReminderText>
            <GreetingSalutation>hello</GreetingSalutation>
            <GreetingName>FirstName</GreetingName>
            <GreetingString>dsfsdfsd</GreetingString>
            <OrganizationName>dsfsdf</OrganizationName>
            <OrganizationAddress1>sdfsdf</OrganizationAddress1>
            <OrganizationAddress2>dsfsdf</OrganizationAddress2>
            <OrganizationAddress3>sdfdsf</OrganizationAddress3>
            <OrganizationCity>fsdf</OrganizationCity>
            <OrganizationState>fsdf</OrganizationState>
            <OrganizationInternationalState>fds</OrganizationInternationalState>
            <OrganizationCountry>fdsf</OrganizationCountry>
            <OrganizationPostalCode>232132</OrganizationPostalCode>
            <IncludeForwardEmail>No</IncludeForwardEmail>
            <ForwardEmailLinkText>No</ForwardEmailLinkText>
            <IncludeSubscribeLink>No</IncludeSubscribeLink>
            <SubscribeLinkText></SubscribeLinkText>
            <EmailContentFormat>HTML</EmailContentFormat>
            <EmailContent>&lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" &#13;xmlns:cctd="http://www.constantcontact.com/cctd"&gt;&#13;&lt;body&gt;&#13;test html&#13;&lt;/body&gt;&#13;&lt;/html&gt;</EmailContent>
            <EmailTextContent>&lt;text&gt;dsfsdfsdfsdfsd&lt;text&gt;</EmailTextContent>
            <StyleSheet></StyleSheet>
            <ContactLists>
                <ContactList id="http://api.constantcontact.com/ws/customers/shameerc/lists/2">
                    <link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/shameerc/lists/2" rel="self"/>
                </ContactList>
            </ContactLists>
            <FromEmail>
                <Email id="http://api.constantcontact.com/ws/customers/shameerc/settings/emailaddresses/1">
                    <link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/shameerc/settings/emailaddresses/1" rel="self"/>
                </Email>
                <EmailAddress>shameer_c@ispg.in</EmailAddress>
            </FromEmail>
            <ReplyToEmail>
                <Email id="http://api.constantcontact.com/ws/customers/shameerc/settings/emailaddresses/1">
                    <link xmlns="http://www.w3.org/2005/Atom" href="http://api.constantcontact.com/ws/customers/shameerc/settings/emailaddresses/1" rel="self"/>
                </Email>
                <EmailAddress>shameer_c@ispg.in</EmailAddress>
            </ReplyToEmail>
        </Campaign>
    </content>
    <source>
        <id>http://api.constantcontact.com/ws/customers/shameerc/campaigns</id>
        <title type="text">Campaigns for customer: shameerc</title>
        <link href="campaigns"/>
        <link href="campaigns" rel="self"/>
        <author>
            <name>shameerc</name>
        </author>
        <updated>2011-07-26T11:08:41+01:00</updated>
    </source>
</entry> 

 

 

Highlighted
Moderator

Re: Getting '400' error while trying to create a campaign using API

The 500 errors are being caused by using No instead of NO for the YES/NO sections.  Changing those values to NO (all caps) will get you creating campaigns.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

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