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.

Newbie Help: Adding a contact, email only

Highlighted
Occasional Contributor

Newbie Help: Adding a contact, email only

I am using PHP and the class provided and I can get an array of all my lists.  However I get an error when trying to add a new user.  Here is my code:

 

//create the CC objects
$ccListOBJ = new CC_List(); 
$ccContactOBJ = new CC_Contact();	
$postFields = array();
$postFields["email_address"] = $emailaddress; //test123@example.com
$postFields["lists"] = $theid; //http://api.constantcontact.com/ws/customers/[username]/lists/2
$contactXML = $ccContactOBJ->createContactXML(null,$postFields);	
if (!$ccContactOBJ->addSubscriber($contactXML)) 
	{
	echo "<br>NOT ADDED<br>";
	} 
else 
	{
	echo "<br>ADDED<br>";
	}	

 and the error I get back is: Invalid argument supplied for foreach() [filepath] on line 491.

 

Any thoughts?

Tags (3)
3 REPLIES 3
Highlighted
Employee

Re: Newbie Help: Adding a contact, email only

Hey Jeffrey,

 

I am unsure of which wrapper you are using but I suggest trying out our wrapper that is on GitHub.  Based on what your trying to do this would be the following code to do what you want with the other wrapper.

 

<?php 
	include ('wrapper/ConstantContact.php');
	
	$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");

	//Get potential contact lists
	$lists = $ConstantContact->getLists();
	
	$contactObj = new Contact();
	$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
	$contactObj->emailAddress = 'test@example.com';
	
	// Create the contact
	$Contact = $ConstantContact->addContact($contactObj);

?>

 Just replace the information at the top with your information in the connection string.  You can find the documentation and the wrapper itself here.

 

If you don't want to use that wrapper please let me know which one you are using so I can trouble shoot this further for you.

 

 

Ryan Davis
Quality Engineer
Tags (1)
Highlighted
Occasional Contributor

Re: Newbie Help: Adding a contact, email only

I am using the PHP sample files on this page which includes a constant contact class.  I may try your method as it looks simpler but just for completeness and for anyone else searching can advise based on the PHP files based on this page (using the simple contact form): http://community.constantcontact.com/t5/Documentation/Code-Samples/ba-p/25019

 

Highlighted
Employee

Re: Newbie Help: Adding a contact, email only

I am glad that helped, please let me know if you need anymore help.

 

 

Ryan Davis
Quality Engineer
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