We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Problem copying a campaign

Occasional Participant

Problem copying a campaign



My client has created several email models on his account. I need to use this models to create new emails that must be sent in certain cases. I thought of doing it like this:


$campaigns = $ConstantContact->getCampaigns();
  foreach($campaigns['campaigns'] as $key=>$campaign)
      if($campaign->name=='Email model name')
           $modelCampaign = $ConstantContact->getCampaignDetails($campaign);

           $myCampaign = new Campaign();
           $myCampaign->name = "Email name based on date ".date('Y-m-d');
           $myCampaign->subject = $modelCampaign ->subject;
           $myCampaign->fromName = $modelCampaign ->fromName;
           $myCampaign->greetingName = $modelCampaign ->greetingName;
           $myCampaign->greetingString = $modelCampaign ->greetingString;
           $myCampaign->emailContentFormat = $modelCampaign ->emailContentFormat;
           $myCampaign->emailContent = $modelCampaign ->emailContent;
           $myCampaign->textVersionContent = $modelCampaign ->textVersionContent ;
           $VerifiedAddresses = $ConstantContact->getVerifiedAddresses();
           $newCampaign = $ConstantContact->addCampaign($myCampaign, $VerifiedAddresses[addresses][0]);


The problem is the new campaign is not created because the $modelCampaign somehow doesn't have all the details. The error i get is:

Constant Contact Campaign Error: 'textVersionContent' was required but not supplied
Constant Contact HTTP Request Exception: Error 400: Error: Line 1: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '((F|f)(I|i)(R|r)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((L|l)(A|a)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((F|f)(I|i)(R|r)(S|s)(T|t)(A|a)(N|n)(D|d)(L|l)(A|a)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((N|n)(O|o)(N|n)(E|e))' for type 'greetingchoices'.

Error: Line 1: cvc-type.3.1.3: The value '' of element 'GreetingName' is not valid.
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in my_path/ctct/Collections.php on line 412

Warning: simplexml_load_string(): Error 400: Error: Line 1: cvc-pattern-valid: Value '' is not facet-valid with re in my_path/ctct/Collections.php on line 412 Warning: simplexml_load_string(): ^ in my_path/ctct/Collections.php on line 412

Fatal error: Call to a member function Attributes() on a non-object in my_path/ctct/Components.php on line 547


Can you please give me any advice?

Thank you


What if you try to set:


$myCampaign = new Campaign();
$myCampaign = $modelCampaign;

 Since the object is that of the same type, I believe that it should make an exact copy as it is of the same type.

Ryan Davis
Quality Engineer
Occasional Participant

Unfortunately that leads to the same error; as if the object returned by the getCampaignDetails method doesn't have all the fields required to create a new campaign. And i don't know another way to select a campaign and copy it...

Try doing something like this,


include 'ConstantContact.php';

$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");

$myVerifiedAddress = $ConstantContact->getVerifiedAddresses();
$fromEmail = $myVerifiedAddress[addresses][0];
$replyEmail = $myVerifiedAddress[addresses][0];
$myCampaigns = $ConstantContact->getCampaigns(); // get all campaigns

do { 
	 // do while so we can see if there are multiple pages.  
	 // This process can take a long time as it handles many requests
	$x = 0; // Start X over for every page of campaigns	
	foreach($myCampaigns[campaigns] as $Campaign[$x])
		echo $Campaign[$x]->id;
		if($Campaign[$x]->id == "http://api.constantcontact.com/ws/customers/{username}/campaigns/{CampaignID}")
			$thisCampaignDetails = $ConstantContact->getCampaignDetails($Campaign[$x]);
			$newCampaign = new Campaign();
			$newCampaign = $thisCampaignDetails;
			$newCampaign->name = rand() . $thisCampaignDetails->name;

}while ($myCampaigns[nextlink] != false);

$ConstantContact->addCampaign($newCampaign, $fromEmail);



Ryan Davis
Quality Engineer
Regular Participant

Hi Ryan,


The above code works well for copying the email campaign.

But is there any specific reason behing getting the details of all the campaigns. The process of getting all the campaigns and comparing if its id matches the one we are trying to copy.


Is there any way of just get the details of single campaign, change the name and add it as a new campaign.

I am getting an error if i try do this way.


Please suggest.







Yes you want to get the campaign details so you can have a FULL campaign object of the data that you wish to copy.  Upon doing a GET To campaigns, it only brings in a summary of data which would not be enough to create your new campaign.  The ID however is returned in the summary. 


I am writing some changes to the wrapper which may make this simpler in the future by adding a new feature:


GetCampaignByID which will return the campaign  details with the campain ID supplied.  This should be released sometime this week.


Let me know if this helps.

Ryan Davis
Quality Engineer
Regular Participant


Thanks for the reply Ryan.

This answers my question. Please let us know once getCampaignByID feature is ready.




Developer Portal

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

Visit Page