Error 400 when creating campaign by API

sonnel
Regular Participant

Error 400 when creating campaign by API

Are there any hints that why the following xml causes error 400?


Thanks!


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

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

    <link href="/ws/customers/myaccount/campaigns" rel="edit"/>

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

    <title>test</title>

    <author>test</author>

    <updated>2010-10-06T09:34:00Z</updated>

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

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

            <Name>Test Campaign</Name>

            <Status>Draft</Status>

            <Date>2010-10-06T09:34:00Z</Date>

            <Subject>test email</Subject>

            <FromName>principal</FromName>

            <ViewAsWebpage>NO</ViewAsWebpage>

            <ViewAsWebpageLinkText></ViewAsWebpageLinkText>

            <ViewAsWebpageText></ViewAsWebpageText>

            <PermissionReminder>YES</PermissionReminder>

            <PermissionReminderText></PermissionReminderText>

            <GreetingSalutation></GreetingSalutation>

            <GreetingName>FirstName</GreetingName>

            <GreetingString></GreetingString>

            <OrganizationName></OrganizationName>

            <OrganizationAddress1></OrganizationAddress1>

            <OrganizationAddress2></OrganizationAddress2>

            <OrganizationAddress3></OrganizationAddress3>

            <OrganizationCity></OrganizationCity>

            <OrganizationState></OrganizationState>

            <OrganizationInternationalState></OrganizationInternationalState>

            <OrganizationCountry></OrganizationCountry>

            <OrganizationPostalCode></OrganizationPostalCode>

            <IncludeForwardEmail>NO</IncludeForwardEmail>

            <ForwardEmailLinkText></ForwardEmailLinkText>

            <IncludeSubscribeLink>NO</IncludeSubscribeLink>

            <SubscribeLinkText></SubscribeLinkText>

            <EmailContentFormat>HTML</EmailContentFormat>

            <EmailContent>

                &lt;html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"xmlns:cctd="http://www.constantcontact.com/cctd"&gt;&lt;body&gt;&lt;OpenTracking/&gt;hi,&lt;br&gt;&lt;br&gt;test test&lt;br&gt;&lt;/body&gt;&lt;/html&gt;

            </EmailContent>

            <EmailTextContent>

            </EmailTextContent>

            <StyleSheet>

            </StyleSheet>

            <ContactLists>

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

                    <link xmlns="http://api.constantcontact.com/ws/customers/myaccount/lists/1" rel="self"/>

                </ContactList>

            </ContactLists>

            <FromEmail>

                <Email id="http://api.constantcontact.com/ws/customers/myaccount/settings/emailaddresses/4">

                    <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/myaccount/settings/emailaddresses/4" rel="self"/>

                </Email>

                <EmailAddress>

                    noreply@school.com

                </EmailAddress>

            </FromEmail>

            <ReplyToEmail>

                <Email id="http://api.constantcontact.com/ws/customers/myaccount/settings/emailaddresses/4">

                    <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/myaccount/settings/emailaddresses/4" rel="self"/>

                </Email>

                <EmailAddress>

                    noreply@school.com

                </EmailAddress>

            </ReplyToEmail>

        </Campaign>

    </content>

    <source>

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

        <title>Campaign from school</title>

        <link href="campaigns"/>

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

        <author>

            <name>school</name>

        </author>

        <updated>2010-10-06T09:34:00Z</updated>

    </source>

</entry>

 

4 REPLIES 4
DaveBerard
Moderator

Looks like there are quite a few problems with the XML in regards to missing required fields (the entire address section is empty and those are all required).  However, the problem that you're stuck on is the list node being incorrect.  Here is the error message I receive when running your XML.


 


Error 400: Error: Line 38: cvc-complex-type.2.4.a: Invalid content was found starting with element 'link'. One of '{"http://www.w3.org/2005/Atom":link, "http://ws.constantcontact.com/ns/1.0/":link}' is expected.

 


When I look at that line, I see that your ContactList data has an invalid xlmns attribute and no href attribute.  Here is the correct XML for that line:


 


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

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

 </ContactList>


 


Once I made that correct, the 400 errors I got back after that reflected missing required content that you would need to fill in.  I saw quickly the entire address section and the text content were all still empty.  Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact
DaveBerard
Moderator

Looks like there are quite a few problems with the XML in regards to missing required fields (the entire address section is empty and those are all required).  However, the problem that you're stuck on is the list node being incorrect.  Here is the error message I receive when running your XML.


 


Error 400: Error: Line 38: cvc-complex-type.2.4.a: Invalid content was found starting with element 'link'. One of '{"http://www.w3.org/2005/Atom":link, "http://ws.constantcontact.com/ns/1.0/":link}' is expected.

 


When I look at that line, I see that your ContactList data has an invalid xlmns attribute and no href attribute.  Here is the correct XML for that line:


 


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

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

 </ContactList>


 


Once I made that correct, the 400 errors I got back after that reflected missing required content that you would need to fill in.  I saw quickly the entire address section and the text content were all still empty.  Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact
sonnel
Regular Participant

Thanks for your reply! I got it working now.


I wonder if there is any way I can verify the xml programmatically.

DaveBerard
Moderator

Many of the rules and checks we have for content can change internally depending on our software changes.  For this reason, we recommend that you have the XML checked against us and use our error response messages to provide the user with feedback.  In most cases, the error messages are very clear and descriptive.  At this time, we do not have any published set of rules for the various nodes outside of our documented ones.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page