Hey Richard,
It looks like you are using our cc_class.php file as a library. This is not really meant to be used as a library but we do have a very user friendly php library under our code samples which you can find here. The code you can use with our new wrapper would be something like this.
<?php
/****************************************************************************************
*
* Please note that this is just an example, please change the credentials to
* your own constant contact login credentials. The following code is an example of:
*
* Search for contact by email address
* Creating a new contact if it doesen't already exist
* If Contact exists, then update the contact by adding it to a new list
*
****************************************************************************************/
// this application uses our new wrapper that can be found on github
// https://github.com/ctctsupport/ctct_php_library
include ('wrapper/ConstantContact.php');
// Connecting to your account
$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");
// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50
// Email address here is used for testing purposes
// NOTE: This email address will be added to your account if you execute this script,
// you should send this to do-not-mail after your testing
$emailAddress = "testemailaddress@testemail.com";
// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);
// If the search didnt return a contact object
if($search == false)
{
echo "Created new contact";
// Create a new Contact Object to store data into
$contactObj = new Contact();
// Adding multiple lists to this new Contact Object
$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
// Set the email address
$contactObj->emailAddress = $emailAddress;
// Create the Contact and DONE
$Contact = $ConstantContact->addContact($contactObj);
echo $contactObj->emailaddress;
} // Otherwise we update our existing
else
{
echo $contactObj->emailaddress . " was added to your new list";
// Gather data from our previous search and store it into a data type
$contactObj = $ConstantContact->getContactDetails($search[0]);
// We need to get the old list and add a new list to it as
// this request requires a PUT and will remove the lists
// as they are stored in an array
array_push($contactObj->lists, $lists['lists'][3]->id );
// Update the contact and DONE
$UpdateContact = $ConstantContact->updateContact($contactObj);
}
?>
Mind you that this does a bit more as it checks to see if it exists, then takes the appropriate actions.
Please let me know if you have any other questions.
... View more