Error 400 when updating campaign

sonnel
Regular Participant

Error 400 when updating campaign

I got error 400 when updating campaign. I PUT the following content to the URL equal to its id (tried both http and https). Somebody please help to find out the problem. Thanks!


 


Here's my xml:


 


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

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

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

    <id>

        http://api.constantcontact.com/ws/customers/myaccount/campaigns/1103756094823

    </id>

    <title type="text">

        Another Campaign

    </title>

    <author>

        <name>

            school

        </name>

    </author>

    <updated>

        2010-10-07T13:49:36Z

    </updated>

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

        <Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/myaccount/campaigns/1103756094823">

            <Name>

                Another Campaign

            </Name>

            <Status>

                Draft

            </Status>

            <Date>

                2010-10-07T13:49:36Z

            </Date>

            <Subject>

            </Subject>

            <FromName>

                sonnel

            </FromName>

            <ViewAsWebpage>

                NO

            </ViewAsWebpage>

            <ViewAsWebpageLinkText>

            </ViewAsWebpageLinkText>

            <ViewAsWebpageText>

            </ViewAsWebpageText>

            <PermissionReminder>

                YES

            </PermissionReminder>

            <PermissionReminderText>

            </PermissionReminderText>

            <GreetingSalutation>

            </GreetingSalutation>

            <GreetingName>

                FirstName

            </GreetingName>

            <GreetingString>

            </GreetingString>

            <OrganizationName>

                Beez

            </OrganizationName>

            <OrganizationAddress1>

                address

            </OrganizationAddress1>

            <OrganizationAddress2>

            </OrganizationAddress2>

            <OrganizationAddress3>

            </OrganizationAddress3>

            <OrganizationCity>

                city

            </OrganizationCity>

            <OrganizationState>

                state

            </OrganizationState>

            <OrganizationInternationalState>

            </OrganizationInternationalState>

            <OrganizationCountry>

                HK

            </OrganizationCountry>

            <OrganizationPostalCode>

                00000

            </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">&lt;body>&lt;OpenTracking/>&lt;opentracking>&lt;/opentracking>&lt;/body>&lt;/html>

            </EmailContent>

            <EmailTextContent>

                &lt;Text>&lt;/Text>

            </EmailTextContent>

            <StyleSheet>

            </StyleSheet>

            <ContactLists>

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

            </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 type="text">

            Campaign from school

        </title>

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

        <author>

            <name>

                school

            </name>

        </author>

        <updated>

            2010-10-07T13:49:36Z

        </updated>

    </source>

</entry>

 

5 REPLIES 5
bsoder
Employee

Hello,



I took a look at your XML and I did see a few problems that once I corrected, I was able to do a successful PUT.



First, I am not sure if this is how it was pasted over or not, but a lot of the spacing was causing an issue for me and I had to remove the spaces in between the nodes in order for it to successfully work in the REST client. Here is the XML that I was able to recreate from yours that did work:



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

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

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

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

<title type="text">Another Campaign</title>

<author><name>school</name></author>

<updated>2010-10-07T13:49:36Z</updated>

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

<Campaign xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/bsoder/campaigns/1103757280092">

<Name>Another Campaign</Name>

<Status>Draft</Status>

<Date>2010-10-07T13:49:36Z</Date>

<Subject>test</Subject>

<FromName>sonnel</FromName>

<ViewAsWebpage>NO</ViewAsWebpage>

<ViewAsWebpageLinkText></ViewAsWebpageLinkText>

<ViewAsWebpageText></ViewAsWebpageText>

<PermissionReminder>NO</PermissionReminder>

<PermissionReminderText></PermissionReminderText>

<GreetingSalutation></GreetingSalutation>

<GreetingName>FirstName</GreetingName>

<GreetingString></GreetingString>

<OrganizationName>Beez</OrganizationName>

<OrganizationAddress1>address</OrganizationAddress1>

<OrganizationAddress2></OrganizationAddress2>

<OrganizationAddress3></OrganizationAddress3>

<OrganizationCity>city</OrganizationCity>

<OrganizationState>MA</OrganizationState>

<OrganizationInternationalState></OrganizationInternationalState>

<OrganizationCountry>US</OrganizationCountry>

<OrganizationPostalCode>00000</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">&lt;body>&lt;OpenTracking/>&lt;opentracking></opentracking>&lt;/body>&lt;/html></EmailContent>

<EmailTextContent>&lt;Text>&lt;/Text></EmailTextContent>

<StyleSheet></StyleSheet>

<ContactLists>

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

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

</ContactList>

</ContactLists>

<FromEmail>

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

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

</Email>

<EmailAddress>

noreply@school.com

</EmailAddress>

</FromEmail>

<ReplyToEmail>

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

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

</Email>

<EmailAddress>

noreply@school.com

</EmailAddress>

</ReplyToEmail>

</Campaign>

</content>

<source>

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

<title type="text">Campaign from school</title>

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

<author>

<name>school</name>

</author>

<updated>

2010-10-07T13:49:36Z

</updated>

</source>

</entry>



Also note that I did add a Subject line, and a correct state abbreviation in the Org State node.  You also had a permission reminder set with no permission reminder text.  That is required.



With those changes it did work for me.  Let me know if you have any further questions.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
sonnel
Regular Participant

Thanks for your help! It fixes the 400 error now by adding back the Subject tag and clear the OrganizationState value (as we're outside US).


 


But I encounter 404 error now. Is it correct to do a PUT to, say in previous example, https://api.constantcontact.com/ws/customers/myaccount/campaigns/1103756094823. Anyway, I tried both http and https with the same error.

sonnel
Regular Participant

By the way, the space was created by a xml formatter. The original xml is in 1 line.

bsoder
Employee

Hello,



A 404 error normally does mean the URI is incorrect. It could also mean that the campagin ID you are doing the PUT to is incorrect. Could you verify that the campaign ID that you have in the URI is the correct campaign ID that you are updating?



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
sonnel
Regular Participant

Yes, you're right! I finally got it fixed. Thanks!

Developer Portal

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

Visit Page