copy a campaign via API

SOLVED
Go to solution
Member

copy a campaign via API

Hi there,

 

We have a campaign that has to be run weekly. Since there is no way in constant and contact to schedule for a recurring campaign, the only way I believe you can do this is to copy a campaign and schedule that to run on a desired date time. Is there a way to make a copy of a campaign through API using the campaign Name? I didn't find any documenation for it or may be i missed one. Please advise..

 

Thanks, Sid

1 ACCEPTED SOLUTION

This is actually a technical problem in the content you're sending over, which is a good thing since it means we're getting close to a solution.  The content of the nodes EmailContent and EmailTextContent must be XML or HTML encoded when sent to Constant Contact via the API.  If you do not encode it, it will certainly cause errors as the XML validation will fail.

 

I also ran into one additional problem which turned out to be a defect on our side, not something you are doing wrong.  I've opened up a defect with our development team to have it fixed in a future release.  In the meantime, you will need to remove the <LastRunDate> node before sending the POST request.  Below is the XML which worked in my account.

 

 

<?xml version="1.0" encoding="UTF-8" ?> 
  <entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/abc/campaigns/1105077954923" rel="edit" />
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns/1105077954923</id>
  <title type="text">Test Custom Template Email - 4</title>
  <updated>2011-04-07T14:45:20.019Z</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/abc/campaigns/1105077954923">
  <Name>Test Custom Template Email - 4</Name>
  <Status>Sent</Status>
  <Date>2011-04-07T14:45:20.019Z</Date>
  <LastEditDate>2011-04-07T14:50:05.454Z</LastEditDate>
  <Sent>7</Sent>
  <Opens>0</Opens>
  <Clicks>0</Clicks>
  <Bounces>0</Bounces>
  <Forwards>0</Forwards>
  <OptOuts>0</OptOuts>
  <SpamReports>0</SpamReports>
  <SharePageURL />
  <Subject>PD Survey Test</Subject>
  <FromName>ABC</FromName>
  <CampaignType>CUSTOM</CampaignType>
  <ViewAsWebpage>YES</ViewAsWebpage>
  <ViewAsWebpageLinkText>Click here</ViewAsWebpageLinkText>
  <ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText>
  <PermissionReminder>NO</PermissionReminder>
  <GreetingSalutation>Dear</GreetingSalutation>
  <GreetingName>FirstName</GreetingName>
  <GreetingString>Greetings!</GreetingString>
  <OrganizationName>ABC</OrganizationName>
  <OrganizationAddress1>123 Main St</OrganizationAddress1>
  <OrganizationAddress2>Suite 100</OrganizationAddress2>
  <OrganizationAddress3 />
  <OrganizationCity>Chicago</OrganizationCity>
  <OrganizationState>IL</OrganizationState>
  <OrganizationInternationalState />
  <OrganizationCountry>us</OrganizationCountry>
  <OrganizationPostalCode>99999</OrganizationPostalCode>
  <IncludeForwardEmail>YES</IncludeForwardEmail>
  <ForwardEmailLinkText>Forward email</ForwardEmailLinkText>
  <IncludeSubscribeLink>YES</IncludeSubscribeLink>
  <SubscribeLinkText>Subscribe me!</SubscribeLinkText>
  <EmailContentFormat>XHTML</EmailContentFormat>
  <EmailContent>&lt;html lang=&quot;en&quot; xml:lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:cctd=&quot;http://www.constantcontact.com/cctd&quot;&gt; &lt;body&gt;&lt;CopyRight&gt;Copyright (c) 1996-2011 Constant Contact. All rights reserved. Except as permitted under a separate written agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on any Constant Contact site, including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, or distributed without the prior written permission of Constant Contact. For inquiries regarding reproduction or distribution of any Constant Contact material, please contact legal@constantcontact.com.&lt;/CopyRight&gt; &lt;OpenTracking/&gt; &lt;!-- Do NOT delete previous line if you want to get statistics on the number of opened emails --&gt; &lt;CustomBlock name=&quot;letter.intro&quot; title=&quot;Personalization&quot;&gt; &lt;Greeting/&gt; &lt;/CustomBlock&gt; &lt;b&gt;Please click on the survey link below.&lt;/b&gt; &lt;Property name=&quot;Subscriber.CustomText1&quot; /&gt;&lt;br /&gt; &lt;Property name=&quot;Subscriber.CustomText2&quot; /&gt; &lt;/body&gt; &lt;/html&gt;</EmailContent>
  <EmailTextContent>&lt;Text&gt;&lt;Greeting/&gt;&lt;/Text&gt;</EmailTextContent>
  <StyleSheet />
  <ArchiveStatus />
  <ArchiveURL />
  <ContactLists>
  <ContactList id="http://api.constantcontact.com/ws/customers/abc/lists/4">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/lists/4" rel="self" />
  </ContactList>
  </ContactLists>
  <FromEmail>
  <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" />
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress>
  </FromEmail>
  <ReplyToEmail>
  <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" />
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress>
  </ReplyToEmail>
  </Campaign>
  </content>
  <source>
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns</id>
  <title type="text">Campaigns for customer: abc</title>
  <link href="campaigns" />
  <link href="campaigns" rel="self" />
  <author>
  <name>abc</name>
  </author>
  <updated>2011-04-07T14:50:05.494Z</updated>
  </source>
  </entry>
Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

16 REPLIES 16
Employee

Hello Sid,

 

Copying a campaign in the API is definitely possible.  The best way to do this would be to do a GET call on the campaign that you would like copied.  You will receive that campaigns XML.  You will want to modify the Campaign Name, then post the XML to the campaign collection URI.

 

You can find more information about performing a GET on the original campaign here, as well as on how to then post the new XML to the campaign collection here.

 

If you have any questions about this please let me know.

Benjamin Soder
NOC Analyst
Constant Contact

 I tried the code below to copy a new campaign but i get an error when i execute my code. "Web Exception: Unsupported media types".

 

 

public void CreateCampaign(string APIKey, string uName, string pWord)
    {
        CredentialCache LoginCredentials = new CredentialCache();
        LoginCredentials.Add(new Uri("https://api.constantcontact.com/ws/customers/" + uName), "Basic", new NetworkCredential(APIKey + '%' + uName, pWord));
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.constantcontact.com/ws/customers/" +
            uName + "/campaigns");
        request.Credentials = LoginCredentials;
        string createCampaign = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> 
        <entry xmlns=""http://www.w3.org/2005/Atom"">
        <link href=""/ws/customers/lennoxpd/campaigns/1105057009223"" rel=""edit"" /> 
        <title type=""text"">" + DateTime.Now.ToShortDateString() + " Email Campaign" + @"</title> 
        <updated>2011-04-04T20:05:07.856Z</updated> 
        <author>
        <name>Constant Contact</name> 
        </author>
        <content type=""application/vnd.ctct+xml"">
        <Name>" + DateTime.Now.ToShortDateString() + " Email Campaign" + @"</Name> 
        <Status>Sent</Status> 
        <Date>2011-04-07T20:05:07.856Z</Date> 
        <LastEditDate>2011-04-06T14:44:56.956Z</LastEditDate> 
        <LastRunDate>2011-04-04T20:05:06.375Z</LastRunDate> 
        <Sent>7</Sent> 
        <Opens>0</Opens> 
        <Clicks>0</Clicks> 
        <Bounces>4</Bounces> 
        <Forwards>0</Forwards> 
        <OptOuts>0</OptOuts> 
        <SpamReports>0</SpamReports> 
        <Subject>Survey program test</Subject> 
        <FromName>Comp A</FromName> 
        <CampaignType>STOCK</CampaignType> 
        <ViewAsWebpage>YES</ViewAsWebpage> 
        <ViewAsWebpageLinkText>Click here</ViewAsWebpageLinkText> 
        <ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText> 
        <PermissionReminder>YES</PermissionReminder> 
        <PermissionReminderText /> 
        <GreetingSalutation /> 
        <GreetingString /> 
        <OrganizationName /> 
        <OrganizationAddress1>6123 Main St</OrganizationAddress1> 
        <OrganizationAddress2>Suite 985</OrganizationAddress2> 
        <OrganizationAddress3 /> 
        <OrganizationCity>City</OrganizationCity> 
        <OrganizationState>State</OrganizationState> 
        <OrganizationInternationalState /> 
        <OrganizationCountry>us</OrganizationCountry> 
        <OrganizationPostalCode>99999</OrganizationPostalCode> 
        <IncludeForwardEmail>YES</IncludeForwardEmail> 
        <ForwardEmailLinkText>Forward email</ForwardEmailLinkText> 
        <IncludeSubscribeLink>YES</IncludeSubscribeLink> 
        <SubscribeLinkText>Subscribe me!</SubscribeLinkText> 
        <ArchiveStatus /> 
        <ArchiveURL /> 
        <ContactLists>
        <link xmlns=""http://www.w3.org/2005/Atom"" href=""/ws/customers/abc/lists/4"" rel=""self"" /> 
        </ContactList>
        </ContactLists>
        <FromEmail>
        <link xmlns=""http://www.w3.org/2005/Atom"" href=""/ws/customers/abc/settings/emailaddresses/1"" rel=""self"" /> 
        </Email>
        <EmailAddress>abc@compa.com</EmailAddress> 
        </FromEmail>
        <ReplyToEmail>
        <link xmlns=""http://www.w3.org/2005/Atom"" href=""/ws/customers/abc/settings/emailaddresses/1"" rel=""self"" /> 
        </Email>
        <EmailAddress>abc@compa.com</EmailAddress> 
        </ReplyToEmail>
        </Campaign>
        </content>
        <source>
        <title type=""text"">Campaigns for customer: abc</title> 
        <link href=""campaigns"" /> 
        <link href=""campaigns"" rel=""self"" /> 
        <author>
        <name>abc</name> 
        </author>
        <updated>2011-04-06T14:44:56.999Z</updated> 
        </source>
        </entry>";
        request.Method = "POST";
        request.ContentType = "text/xml";
        UTF8Encoding encoding = new UTF8Encoding();
        byte[] byteArray = encoding.GetBytes(createCampaign);
        try
        {
            request.ContentLength = byteArray.Length;
            string XMLResponse = "Bytes to send: " + byteArray.Length;
            Stream streamRequest = request.GetRequestStream();
            streamRequest.Write(byteArray, 0, byteArray.Length);
            streamRequest.Close();
            HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
            StreamReader Reader = new StreamReader(Response.GetResponseStream());
            XMLResponse += Response.StatusCode + Response.StatusDescription + Reader.ReadToEnd();
            Reader.Close();
            Response.Close();
            //return XMLResponse;
        }
        catch (WebException e)
        {
            throw new WebException("WebException: " + e.Status + "With response: " + e.Message);
        }
        catch (Exception e)
        {
            throw new Exception("Exception: " + e.Message);
        }
    }

 

 

I changed my content type to "application/atom+xml", and now i get a 400 Bad Request error.

400 Bad Request generally indicates that information you sent over is bad or invalid.  To get the full error message, add the following two lines to your Catch block for the WebException:

 

StreamReader s = new StreamReader(e.Response.GetResponseStream());
String FullResponse = s.ReadToEnd(); 

 

The value in FullResponse will give you our error feedback so you can actually see the error in the XML.  If you can follow up with the actual content you're getting in that response, we can provide you with a better direction to go in correcting it.

Dave Berard
Senior Product Manager, Constant Contact

This is what i get now.

 

WebException: ProtocolErrorWith response: The remote server returned an error: (400) Bad Request.Full Detail: Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>.

I did notice there is a possible problem with your XML content, potentially caused by what you're trying to do.  The Campaign Type is set as STOCK, which indicates you are trying to create a Campaign that uses one of our templates. 

 

This is not currently possible, Campaigns using our templates are only able to be created through our web UI.  While we allow you to get information on them through the API, such as statistics and details, you can not create one via the API.  This is likely the cause of your 400 error as you are both missing required fields (<EmailContent> and <EmailTextContent>) and passing in an invalid value for <CampaignType> (STOCK where only HTML or XHTML are allowed in a POST request). 

 

If your use case is to copy and use a template based Campaign, this is not possible through the API.  Only custom HTML/XHTML templates are usable through this API feature.

Dave Berard
Senior Product Manager, Constant Contact

So, i would have to create an email template in constant and contact using custom html template then, correct? Is there an option where i can do that rather than having you guys create it? 

 

I see a button "Want a custom template? Let us create it" but don't see anywhere i could create one of my own. Please let me know.

The option of Custom HTML/XHTML code means that you are able to use the HTML/XHTML content for an email that you or your design group created.  For more information on how this works in your standard account, you can use the steps in this FAQ: http://constantcontact.custhelp.com/cgi-bin/constantcontact.cfg/php/enduser/std_adp.php?p_faqid=1357...

 

The same details apply when using this through our API features.  If you have your own custom HTML or XHTML email content, you can use that through the API features you're leveraging today.  If you do not have your own custom HTML or XHTML code, this option may not be for you.  The "Create a custom Template" service you are talking about is not able to be used through the API either, I would not recommend this as a solution for you for this reason.

Dave Berard
Senior Product Manager, Constant Contact

Hi Dave,

 

If i do a custom template, would i be able to drag fields to the body? There are few fields that i have to pass from the list to the body of an email. When i was building a custom template, i didn't see an option to add fields to the body.

 

Also, since i will be copying a campaign via API, do I need to create the body each time i do that or is that a one time thing. Where by passing the campaign ID, the contents as well as the list will all be copied. 

 

Not sure if I explained myself very clear here.

Clarification questions were great, believe I have a good understanding of what you're looking to do.  Let me try to give as detailed of answers as I can for each question and hopefully we'll have you up and running.

 

You can certainly add Subscriber details (I.E. FirstName, Address1, CustomField1, etc) to a custom XHTML email, you will need to add some additional XHTML tags that we provide for inserting the data.  We have a guide that goes over this in detail, including all the options you can customize and change.  You can find that guide here: http://img.constantcontact.com/docs/pdf/building-your-emails-with-the-advanced-editor-tool-constant-...

 

If you run into any problems with the XHTML tags or using our Custom Code features, we do offer advanced phone support on this through our standard phone support.  Since this feature is part of our normal product, and we just expose it through the API, any questions on this will be best answered through our phone support as you'll get good clarification and instant support.  Would recommend calling them and asking for help using Custom Code at 1-866-289-2101 if you do end up needing that assitance.

 

The copy campaign flow questions make a lot of sense, I think the confusion is on what it means to "copy" a campaing through the API.  As you've seen, there is no direct API method for "copy", it's actually a multi-step process to create the copy that simulates it.  Here is the flow:

  1. Get the details of an existing custom code campaign using a GET request in the API
  2. (Optional) Update the contents of the email, such as Subject and Body, to reflect any changes you need
  3. Create a new campaign using the data from steps 1 & 2 above and POST a request to the API to create the new campaign.  Keep in mind, the one REQUIRED field to be changed is Name.  This is a unique indentifier in our system so it will need to be changed even if you make an exact copy and skip step 2.

The List(s) associated with a campaign are actually a seperate entity.  They are a collection of Contacts that you want to receive something through one of our products.  When you associate the List(s) with a Campaign and then create a new "copy" of the Campaign using the steps above, it will actually not modify the List(s) in any way.  All you will do is tell us that when the Campaign is finally sent, you just want the Campaign sent to the current members of those selected List(s).

 

Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact

Thanks Dave for the guide. I was able to build a custom template and pass the required custom fields in my body of the email. However, when I try to make a copy of this campaign via API, I run into the following error.

 

 

WebException: ProtocolErrorWith response: The remote server returned an error: (400) Bad Request.Full Detail: Error 400: Error: Line 6: cvc-complex-type.2.4.a: Invalid content was found starting with element 'LastRunDate'. One of '{"http://ws.constantcontact.com/ns/1.0/":PermissionReminder, "http://ws.constantcontact.com/ns/1.0/":PermissionReminderText, "http://ws.constantcontact.com/ns/1.0/":Subject, "http://ws.constantcontact.com/ns/1.0/":FromName, "http://ws.constantcontact.com/ns/1.0/":ViewAsWebpage, "http://ws.constantcontact.com/ns/1.0/":ViewAsWebpageLinkText, "http://ws.constantcontact.com/ns/1.0/":ViewAsWebpageText, "http://ws.constantcontact.com/ns/1.0/":Sent, "http://ws.constantcontact.com/ns/1.0/":Opens, "http://ws.constantcontact.com/ns/1.0/":Clicks, "http://ws.constantcontact.com/ns/1.0/":Bounces, "http://ws.constantcontact.com/ns/1.0/":Forwards, "http://ws.constantcontact.com/ns/1.0/":OptOuts, "http://ws.constantcontact.com/ns/1.0/":SpamReports, "http://ws.constantcontact.com/ns/1.0/":CampaignType, "http://ws.constantcontact.com/ns/1.0/":EmailContent, "http://ws.constantcontact.com/ns/1.0/":EmailTextContent, "http://ws.constantcontact.com/ns/1.0/":EmailContentFormat, "http://ws.constantcontact.com/ns/1.0/":StyleSheet, "http://ws.constantcontact.com/ns/1.0/":ContactLists, "http://ws.constantcontact.com/ns/1.0/":FromEmail, "http://ws.constantcontact.com/ns/1.0/":ReplyToEmail, "http://ws.constantcontact.com/ns/1.0/":GreetingSalutation, "http://ws.constantcontact.com/ns/1.0/":GreetingName, "http://ws.constantcontact.com/ns/1.0/":GreetingString, "http://ws.constantcontact.com/ns/1.0/":OrganizationName, "http://ws.constantcontact.com/ns/1.0/":OrganizationAddress1, "http://ws.constantcontact.com/ns/1.0/":OrganizationAddress2, "http://ws.constantcontact.com/ns/1.0/":OrganizationAddress3, "http://ws.constantcontact.com/ns/1.0/":OrganizationCity, "http://ws.constantcontact.com/ns/1.0/":OrganizationState, "http://ws.constantcontact.com/ns/1.0/":OrganizationInternationalState, "http://ws.constantcontact.com/ns/1.0/":OrganizationPostalCode, "http://ws.constantcontact.com/ns/1.0/":OrganizationCountry, "http://ws.constantcontact.com/ns/1.0/":IncludeForwardEmail, "http://ws.constantcontact.com/ns/1.0/":ForwardEmailLinkText, "http://ws.constantcontact.com/ns/1.0/":IncludeSubscribeLink, "http://ws.constantcontact.com/ns/1.0/":SubscribeLinkText, "http://ws.constantcontact.com/ns/1.0/":ArchiveStatus, "http://ws.constantcontact.com/ns/1.0/":ArchiveURL, "http://ws.constantcontact.com/ns/1.0/":SharePageURL, "http://ws.constantcontact.com/ns/1.0/":NextRunDate, "http://ws.constantcontact.com/ns/1.0/":Urls}' is expected.
Error: Line 39: cvc-type.3.1.2: Element 'EmailContent' is a simple type, so it must have no element information item [children].
Error: Line 40: cvc-type.3.1.2: Element 'EmailTextContent' is a simple type, so it must have no element information item [children].

 

 

This is my xml. All I did was made changes to <Name>...

 

 

<?xml version="1.0" encoding="UTF-8" ?> 
- <entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/abc/campaigns/1105077954923" rel="edit" /> 
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns/1105077954923</id> 
  <title type="text">Test Custom Template Email - 4</title> 
  <updated>2011-04-07T14:45:20.019Z</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/abc/campaigns/1105077954923">
  <Name>Test Custom Template Email - 4</Name> 
  <Status>Sent</Status> 
  <Date>2011-04-07T14:45:20.019Z</Date> 
  <LastEditDate>2011-04-07T14:50:05.454Z</LastEditDate> 
  <LastRunDate>2011-04-07T14:45:19.999Z</LastRunDate> 
  <Sent>7</Sent> 
  <Opens>0</Opens> 
  <Clicks>0</Clicks> 
  <Bounces>0</Bounces> 
  <Forwards>0</Forwards> 
  <OptOuts>0</OptOuts> 
  <SpamReports>0</SpamReports> 
  <SharePageURL /> 
  <Subject>PD Survey Test</Subject> 
  <FromName>ABC</FromName> 
  <CampaignType>CUSTOM</CampaignType> 
  <ViewAsWebpage>YES</ViewAsWebpage> 
  <ViewAsWebpageLinkText>Click here</ViewAsWebpageLinkText> 
  <ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText> 
  <PermissionReminder>NO</PermissionReminder> 
  <GreetingSalutation>Dear</GreetingSalutation> 
  <GreetingName>FirstName</GreetingName> 
  <GreetingString>Greetings!</GreetingString> 
  <OrganizationName>ABC</OrganizationName> 
  <OrganizationAddress1>123 Main St</OrganizationAddress1> 
  <OrganizationAddress2>Suite 100</OrganizationAddress2> 
  <OrganizationAddress3 /> 
  <OrganizationCity>Chicago</OrganizationCity> 
  <OrganizationState>IL</OrganizationState> 
  <OrganizationInternationalState /> 
  <OrganizationCountry>us</OrganizationCountry> 
  <OrganizationPostalCode>99999</OrganizationPostalCode> 
  <IncludeForwardEmail>YES</IncludeForwardEmail> 
  <ForwardEmailLinkText>Forward email</ForwardEmailLinkText> 
  <IncludeSubscribeLink>YES</IncludeSubscribeLink> 
  <SubscribeLinkText>Subscribe me!</SubscribeLinkText> 
  <EmailContentFormat>XHTML</EmailContentFormat> 
  <EmailContent><html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:cctd="http://www.constantcontact.com/cctd"> <body><CopyRight>Copyright (c) 1996-2011 Constant Contact. All rights reserved. Except as permitted under a separate written agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on any Constant Contact site, including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, or distributed without the prior written permission of Constant Contact. For inquiries regarding reproduction or distribution of any Constant Contact material, please contact legal@constantcontact.com.</CopyRight> <OpenTracking/> <!-- Do NOT delete previous line if you want to get statistics on the number of opened emails --> <CustomBlock name="letter.intro" title="Personalization"> <Greeting/> </CustomBlock> <b>Please click on the survey link below.</b> <Property name="Subscriber.CustomText1" /><br /> <Property name="Subscriber.CustomText2" /> </body> </html></EmailContent> 
  <EmailTextContent><Text><Greeting/></Text></EmailTextContent> 
  <StyleSheet /> 
  <ArchiveStatus /> 
  <ArchiveURL /> 
+ <ContactLists>
- <ContactList id="http://api.constantcontact.com/ws/customers/abc/lists/4">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/lists/4" rel="self" /> 
  </ContactList>
  </ContactLists>
- <FromEmail>
- <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" /> 
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress> 
  </FromEmail>
- <ReplyToEmail>
- <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" /> 
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress> 
  </ReplyToEmail>
  </Campaign>
  </content>
- <source>
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns</id> 
  <title type="text">Campaigns for customer: abc</title> 
  <link href="campaigns" /> 
  <link href="campaigns" rel="self" /> 
- <author>
  <name>abc</name> 
  </author>
  <updated>2011-04-07T14:50:05.494Z</updated> 
  </source>
  </entry>

 

 

This is actually a technical problem in the content you're sending over, which is a good thing since it means we're getting close to a solution.  The content of the nodes EmailContent and EmailTextContent must be XML or HTML encoded when sent to Constant Contact via the API.  If you do not encode it, it will certainly cause errors as the XML validation will fail.

 

I also ran into one additional problem which turned out to be a defect on our side, not something you are doing wrong.  I've opened up a defect with our development team to have it fixed in a future release.  In the meantime, you will need to remove the <LastRunDate> node before sending the POST request.  Below is the XML which worked in my account.

 

 

<?xml version="1.0" encoding="UTF-8" ?> 
  <entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/abc/campaigns/1105077954923" rel="edit" />
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns/1105077954923</id>
  <title type="text">Test Custom Template Email - 4</title>
  <updated>2011-04-07T14:45:20.019Z</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/abc/campaigns/1105077954923">
  <Name>Test Custom Template Email - 4</Name>
  <Status>Sent</Status>
  <Date>2011-04-07T14:45:20.019Z</Date>
  <LastEditDate>2011-04-07T14:50:05.454Z</LastEditDate>
  <Sent>7</Sent>
  <Opens>0</Opens>
  <Clicks>0</Clicks>
  <Bounces>0</Bounces>
  <Forwards>0</Forwards>
  <OptOuts>0</OptOuts>
  <SpamReports>0</SpamReports>
  <SharePageURL />
  <Subject>PD Survey Test</Subject>
  <FromName>ABC</FromName>
  <CampaignType>CUSTOM</CampaignType>
  <ViewAsWebpage>YES</ViewAsWebpage>
  <ViewAsWebpageLinkText>Click here</ViewAsWebpageLinkText>
  <ViewAsWebpageText>Having trouble viewing this email?</ViewAsWebpageText>
  <PermissionReminder>NO</PermissionReminder>
  <GreetingSalutation>Dear</GreetingSalutation>
  <GreetingName>FirstName</GreetingName>
  <GreetingString>Greetings!</GreetingString>
  <OrganizationName>ABC</OrganizationName>
  <OrganizationAddress1>123 Main St</OrganizationAddress1>
  <OrganizationAddress2>Suite 100</OrganizationAddress2>
  <OrganizationAddress3 />
  <OrganizationCity>Chicago</OrganizationCity>
  <OrganizationState>IL</OrganizationState>
  <OrganizationInternationalState />
  <OrganizationCountry>us</OrganizationCountry>
  <OrganizationPostalCode>99999</OrganizationPostalCode>
  <IncludeForwardEmail>YES</IncludeForwardEmail>
  <ForwardEmailLinkText>Forward email</ForwardEmailLinkText>
  <IncludeSubscribeLink>YES</IncludeSubscribeLink>
  <SubscribeLinkText>Subscribe me!</SubscribeLinkText>
  <EmailContentFormat>XHTML</EmailContentFormat>
  <EmailContent>&lt;html lang=&quot;en&quot; xml:lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:cctd=&quot;http://www.constantcontact.com/cctd&quot;&gt; &lt;body&gt;&lt;CopyRight&gt;Copyright (c) 1996-2011 Constant Contact. All rights reserved. Except as permitted under a separate written agreement with Constant Contact, neither the Constant Contact software, nor any content that appears on any Constant Contact site, including but not limited to, web pages, newsletters, or templates may be reproduced, republished, repurposed, or distributed without the prior written permission of Constant Contact. For inquiries regarding reproduction or distribution of any Constant Contact material, please contact legal@constantcontact.com.&lt;/CopyRight&gt; &lt;OpenTracking/&gt; &lt;!-- Do NOT delete previous line if you want to get statistics on the number of opened emails --&gt; &lt;CustomBlock name=&quot;letter.intro&quot; title=&quot;Personalization&quot;&gt; &lt;Greeting/&gt; &lt;/CustomBlock&gt; &lt;b&gt;Please click on the survey link below.&lt;/b&gt; &lt;Property name=&quot;Subscriber.CustomText1&quot; /&gt;&lt;br /&gt; &lt;Property name=&quot;Subscriber.CustomText2&quot; /&gt; &lt;/body&gt; &lt;/html&gt;</EmailContent>
  <EmailTextContent>&lt;Text&gt;&lt;Greeting/&gt;&lt;/Text&gt;</EmailTextContent>
  <StyleSheet />
  <ArchiveStatus />
  <ArchiveURL />
  <ContactLists>
  <ContactList id="http://api.constantcontact.com/ws/customers/abc/lists/4">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/lists/4" rel="self" />
  </ContactList>
  </ContactLists>
  <FromEmail>
  <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" />
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress>
  </FromEmail>
  <ReplyToEmail>
  <Email id="http://api.constantcontact.com/ws/customers/abc/settings/emailaddresses/1">
  <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/abc/settings/emailaddresses/1" rel="self" />
  </Email>
  <EmailAddress>xyz@abc.com</EmailAddress>
  </ReplyToEmail>
  </Campaign>
  </content>
  <source>
  <id>http://api.constantcontact.com/ws/customers/abc/campaigns</id>
  <title type="text">Campaigns for customer: abc</title>
  <link href="campaigns" />
  <link href="campaigns" rel="self" />
  <author>
  <name>abc</name>
  </author>
  <updated>2011-04-07T14:50:05.494Z</updated>
  </source>
  </entry>
Dave Berard
Senior Product Manager, Constant Contact

View solution in original post

Thank You very much. It now copied the campaign. One last question, would i be able to schedule this copied campaign to run a particular date using the API..or is this something i have to do via the web interface.

 

Thanks again for your tremendous support on this. Your help is very much appreciated.

We do provide a limited access API for scheduling that is available upon application and approval.  If you're looking for that, you will need to send a request to our AppConnect team.  You can do that by sending an email with the following information:

 

  1. Can you briefly describe your integration and how the Scheduling APIs will fit in?
  2. Who will be using the software integration you are designing to send email campaigns?
  3. Will this integration be available to more than one Constant Contact Account?
  4. What is your estimated frequency of sending using the Scheduling APIs?
  5. How will users of your integration know that they are using Constant Contact to send their email campaigns?
  6. Your Constant Contact Username and API Key

Once we receive this information, a follow up with request status and any follow up information will be sent in 1-2 business days.  Please send the request to our AppConnect Team

 

Dave Berard
Senior Product Manager, Constant Contact

Thanks Dave.

 

I have emailed to App team answering all your questions. Looking forward to hear from you guys. Once again, thanks a bunch for all your help.

Developer Portal

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

Visit Page