cancel
Showing results for 
Search instead for 
Did you mean: 

Newbie Help: Adding a contact, email only

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

 

CTCT 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