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.

Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

SOLVED
Go to solution
Highlighted
Occasional Participant

Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

Hello, I'm trying to add a Campaign, I've seen many posts here complaining about a 400 error when trying to add a campaign, I've seen the posts and I don't seem to find what's wrong with my XML.

 

I'm using the PHP code samples found in this site, using CC_Campaign::addCampaign() It calls https://api.constantcontact.com/ws/customers/testini/campaigns in POST mode.

 

Could you tell me what's wrong with this XML?

 

PS: most of this is just test data. ( {{e-mail address}} appears on purpose, you know, Spam... )

 

Thanks!

 

?xml version="1.0" encoding="UTF-8"?
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/testini/campaigns" rel="edit"/>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Mailing Campaign Akvinta-ID: 12</title>
<updated>2012-03-05T18:10:35+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/testini/campaigns/1100546096289">
<Name>Mailing Campaign Akvinta-ID: 12</Name>
<Status>Draft</Status>
<Date>2012-03-05T18:10:35 01:00</Date>
<Subject>Mailing Campaign Akvinta-ID: 12</Subject>
<FromName>Akvinta</FromName>
<ViewAsWebpage>YES</ViewAsWebpage>
<ViewAsWebpageLinkText>View this e-mail in your browser</ViewAsWebpageLinkText>
<ViewAsWebpageText>View this e-mail in your browser</ViewAsWebpageText>
<PermissionReminder>YES</PermissionReminder>
<PermissionReminderText>Please &lt;ConfirmOptin>&lt;a>confirm&lt;/a>&lt;/ConfirmOptin>.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstAndLastName</GreetingName>
<GreetingString></GreetingString>
<OrganizationName>Akvinta</OrganizationName>
<OrganizationAddress1>Org Address 1</OrganizationAddress1>
<OrganizationAddress2>Org Address 2</OrganizationAddress2>
<OrganizationAddress3>Org Address 3</OrganizationAddress3>
<OrganizationCity>Los Angeles</OrganizationCity>
<OrganizationState>CA</OrganizationState>
<OrganizationInternationalState></OrganizationInternationalState>
<OrganizationCountry>us</OrganizationCountry>
<OrganizationPostalCode></OrganizationPostalCode>
<IncludeForwardEmail>YES</IncludeForwardEmail>
<ForwardEmailLinkText>Forward this email to a friend</ForwardEmailLinkText>
<IncludeSubscribeLink>YES</IncludeSubscribeLink>
<SubscribeLinkText>Subscribe</SubscribeLinkText>
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>Test Text</EmailContent>
<EmailTextContent>&lt;Text&gt;Test Text&lt;/Text&gt;</EmailTextContent>
<StyleSheet></StyleSheet>
<ContactLists>
	<ContactList id="http://api.constantcontact.com/ws/customers/testini/lists/11">
		<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/testini/lists/11" rel="self"/>
	</ContactList>
</ContactLists>
<FromEmail>
	<Email id="">
		<link xmlns="http://www.w3.org/2005/Atom" href="" rel="self"/>
	</Email>
	<EmailAddress>{{e-mail address}}</EmailAddress>
</FromEmail>
<ReplyToEmail>
	<Email id="">
		<link xmlns="http://www.w3.org/2005/Atom" href="" rel="self"/>
	</Email>
	<EmailAddress>{{e-mail address}}</EmailAddress>
</ReplyToEmail>
</Campaign>

</content>
<source>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Campaigns for customer: testini</title>
<link href="campaigns"/>
<link href="campaigns" rel="self"/>
<author>
<name>testini</name>
</author>
<updated>2012-03-05T18:10:35+01:00</updated>
</source>
</entry>

 [*Note from a CTCT Community Admin: I removed the beginning and ending brackets from the "?xml version="1.0"?..." line in your post above because that line breaks the "Developer Support" tab in our CTCT "Labs JMML Q&A" Facebook app (apparently, the app is trying to render that line as is, which wouldn't be acceptable in the middle of a page).]

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

Hey,

 

I took a look through and noticed one or two things that may have caused the errors, then tested a working XML feed that I'll post below.

 

First, the email content needs to have html and body tags to be considered "proper" content by our api. The only other thing I found was the improper formatting of the from and reply-to email addresses...but it looks like you just filtered that out. I put some dummy information in my feed. One other thing I would note is, when putting tags into the email content or text content, you only need the &lt; to replace the < characters. You can leave the > characters intact without breaking the feed.

 

?xml version="1.0" encoding="UTF-8"?
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/testini/campaigns" rel="edit"/>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Mailing Campaign Akvinta-ID: 12</title>
<updated>2012-03-05T18:10:35+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/testini/campaigns/1100546096289">
<Name>Mailing Campaign Akvinta-ID: 12</Name>
<Status>Draft</Status>
<Date>2012-03-05T18:10:35 01:00</Date>
<Subject>Mailing Campaign Akvinta-ID: 12</Subject>
<FromName>Akvinta</FromName>
<ViewAsWebpage>YES</ViewAsWebpage>
<ViewAsWebpageLinkText>View this e-mail in your browser</ViewAsWebpageLinkText>
<ViewAsWebpageText>View this e-mail in your browser</ViewAsWebpageText>
<PermissionReminder>YES</PermissionReminder>
<PermissionReminderText>Please &lt;ConfirmOptin>&lt;a>confirm&lt;/a>&lt;/ConfirmOptin>.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstAndLastName</GreetingName>
<GreetingString></GreetingString>
<OrganizationName>Akvinta</OrganizationName>
<OrganizationAddress1>Org Address 1</OrganizationAddress1>
<OrganizationAddress2>Org Address 2</OrganizationAddress2>
<OrganizationAddress3>Org Address 3</OrganizationAddress3>
<OrganizationCity>Los Angeles</OrganizationCity>
<OrganizationState>CA</OrganizationState>
<OrganizationInternationalState></OrganizationInternationalState>
<OrganizationCountry>us</OrganizationCountry>
<OrganizationPostalCode></OrganizationPostalCode>
<IncludeForwardEmail>YES</IncludeForwardEmail>
<ForwardEmailLinkText>Forward this email to a friend</ForwardEmailLinkText>
<IncludeSubscribeLink>YES</IncludeSubscribeLink>
<SubscribeLinkText>Subscribe</SubscribeLinkText>
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>&lt;html>&lt;body>Test Text&lt;/body>&lt;/html></EmailContent>
<EmailTextContent>&lt;Text>Test Text&lt;/Text></EmailTextContent>
<StyleSheet></StyleSheet>
<ContactLists>
	<ContactList id="http://api.constantcontact.com/ws/customers/testini/lists/11">
		<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/testini/lists/11" rel="self"/>
	</ContactList>
</ContactLists>
<FromEmail>
	<Email id="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1">
		<link xmlns="http://www.w3.org/2005/Atom" href="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1" rel="self"/>
	</Email>
	<EmailAddress>email@verified.com</EmailAddress>
</FromEmail>
<ReplyToEmail>
	<Email id="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1">
		<link xmlns="http://www.w3.org/2005/Atom" href="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1" rel="self"/>
	</Email>
	<EmailAddress>email@verified.com</EmailAddress>
</ReplyToEmail>
</Campaign>

</content>
<source>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Campaigns for customer: testini</title>
<link href="campaigns"/>
<link href="campaigns" rel="self"/>
<author>
<name>testini</name>
</author>
<updated>2012-03-05T18:10:35+01:00</updated>
</source>
</entry>

 [*Note from a CTCT Community Admin: I removed the beginning and ending brackets from the "?xml version="1.0"..." line in your post above because that line breaks the "Developer Support" tab in our CTCT "Labs JMML Q&A" Facebook app (apparently, the app is trying to render that line as is, which wouldn't be acceptable in the middle of a page).]

Nick Galbraith
Support Engineer

View solution in original post

4 REPLIES 4
Highlighted
Moderator

Re: Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

Hey,

 

I took a look through and noticed one or two things that may have caused the errors, then tested a working XML feed that I'll post below.

 

First, the email content needs to have html and body tags to be considered "proper" content by our api. The only other thing I found was the improper formatting of the from and reply-to email addresses...but it looks like you just filtered that out. I put some dummy information in my feed. One other thing I would note is, when putting tags into the email content or text content, you only need the &lt; to replace the < characters. You can leave the > characters intact without breaking the feed.

 

?xml version="1.0" encoding="UTF-8"?
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/testini/campaigns" rel="edit"/>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Mailing Campaign Akvinta-ID: 12</title>
<updated>2012-03-05T18:10:35+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/testini/campaigns/1100546096289">
<Name>Mailing Campaign Akvinta-ID: 12</Name>
<Status>Draft</Status>
<Date>2012-03-05T18:10:35 01:00</Date>
<Subject>Mailing Campaign Akvinta-ID: 12</Subject>
<FromName>Akvinta</FromName>
<ViewAsWebpage>YES</ViewAsWebpage>
<ViewAsWebpageLinkText>View this e-mail in your browser</ViewAsWebpageLinkText>
<ViewAsWebpageText>View this e-mail in your browser</ViewAsWebpageText>
<PermissionReminder>YES</PermissionReminder>
<PermissionReminderText>Please &lt;ConfirmOptin>&lt;a>confirm&lt;/a>&lt;/ConfirmOptin>.</PermissionReminderText>
<GreetingSalutation>Dear</GreetingSalutation>
<GreetingName>FirstAndLastName</GreetingName>
<GreetingString></GreetingString>
<OrganizationName>Akvinta</OrganizationName>
<OrganizationAddress1>Org Address 1</OrganizationAddress1>
<OrganizationAddress2>Org Address 2</OrganizationAddress2>
<OrganizationAddress3>Org Address 3</OrganizationAddress3>
<OrganizationCity>Los Angeles</OrganizationCity>
<OrganizationState>CA</OrganizationState>
<OrganizationInternationalState></OrganizationInternationalState>
<OrganizationCountry>us</OrganizationCountry>
<OrganizationPostalCode></OrganizationPostalCode>
<IncludeForwardEmail>YES</IncludeForwardEmail>
<ForwardEmailLinkText>Forward this email to a friend</ForwardEmailLinkText>
<IncludeSubscribeLink>YES</IncludeSubscribeLink>
<SubscribeLinkText>Subscribe</SubscribeLinkText>
<EmailContentFormat>HTML</EmailContentFormat>
<EmailContent>&lt;html>&lt;body>Test Text&lt;/body>&lt;/html></EmailContent>
<EmailTextContent>&lt;Text>Test Text&lt;/Text></EmailTextContent>
<StyleSheet></StyleSheet>
<ContactLists>
	<ContactList id="http://api.constantcontact.com/ws/customers/testini/lists/11">
		<link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/testini/lists/11" rel="self"/>
	</ContactList>
</ContactLists>
<FromEmail>
	<Email id="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1">
		<link xmlns="http://www.w3.org/2005/Atom" href="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1" rel="self"/>
	</Email>
	<EmailAddress>email@verified.com</EmailAddress>
</FromEmail>
<ReplyToEmail>
	<Email id="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1">
		<link xmlns="http://www.w3.org/2005/Atom" href="https://api.constantcontact.com/ws/customers/testini/settings/emailaddresses/1" rel="self"/>
	</Email>
	<EmailAddress>email@verified.com</EmailAddress>
</ReplyToEmail>
</Campaign>

</content>
<source>
<id>http://api.constantcontact.com/ws/customers/testini/campaigns</id>
<title type="text">Campaigns for customer: testini</title>
<link href="campaigns"/>
<link href="campaigns" rel="self"/>
<author>
<name>testini</name>
</author>
<updated>2012-03-05T18:10:35+01:00</updated>
</source>
</entry>

 [*Note from a CTCT Community Admin: I removed the beginning and ending brackets from the "?xml version="1.0"..." line in your post above because that line breaks the "Developer Support" tab in our CTCT "Labs JMML Q&A" Facebook app (apparently, the app is trying to render that line as is, which wouldn't be acceptable in the middle of a page).]

Nick Galbraith
Support Engineer

View solution in original post

Highlighted
Occasional Participant

Re: Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

Thanks Nick.

I've added the html and body tags, and also left the > characters without conversion (although it's not mandatory) but I still get a 400 error.

 

You say this XML you posted was tested and worked ok?

 

Could it be because I'm using basic authentication? I've been creating, editing and listing contacts and lists and everything worked alright.

Highlighted
Moderator

Re: Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

I was able to POST that code successfully (replacing your account information with my own). I would suggest using RESTClient to troubleshoot what you're seeing. Using RESTClient, you can not only get a body response that can help troubleshoot the issue, but you can also save the request as a .RCQ file and email it to us at webservices@constantcontact.com, so we can do some testing with it there.

 

Hope this helps! Let me know if you have any questions.

Nick Galbraith
Support Engineer
Highlighted
Occasional Participant

Re: Yet another 400 error when trying to Add a Campaign. Is this XML wrong?

I diff'd your XML and mine, and discovered I was leaving the <FromEmail><Email id=""> ID blank.

Now it works.

 

I'll definitely take a look at RESTClient

 

Thanks again.

 

[solved]

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