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.

adding a contact to a list using php assistance...

BrooksW2
Participant

adding a contact to a list using php assistance...

I downloaded the php wrapper and am having issues modifying the addContact.php....

 

I basically just need the php code needed to add an email address to list ID 7....

 

include_once('../ConstantContact.php');
$username = xxx';
$apiKey = 'xxx';
$consumerSecret = 'xxx';
$Datastore = new CTCTDataStore();
$DatastoreUser = $Datastore->lookupUser($username);

 

$Contact = new Contact();
$Contact->emailAddress = "$email";
$Contact->lists = $lists['lists'][7]->id );

$NewContact = $ConstantContact->addContact($Contact);

 

 

the issue has to do with how to set the list to ID 7...

 

thanks!

1 REPLY 1
DaveBerard
Moderator

The one piece you're missing is that the lists field in the $Contact object must be an array (since you can have 0 or more lists associated with a Contact).  Just change this line line to:

 

$Contact->lists = array($lists['lists'][7]->id);

 

That should be the only change you need, the rest of your code looks quite right.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page