Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Contacts

rdaviscc edited this page Sep 29, 2011 · 9 revisions

Add a new contact

<?php  
//Get potential contact lists
$lists = $ConstantContact->getLists();

$contactObj = new Contact();
$contactObj->lists = array($lists['lists'][0]->id, $lists['lists'][1]->id);
$contactObj->emailAddress = 'example@example.com';

// Create the contact
$Contact = $ConstantContact->addContact($contactObj);
?>

Get a list of contacts

<?php
// Get the first page of contacts
$Contacts = $ConstantContact->getContacts();   

// Get a second page of contacts  
$moreContacts = $ConstantContact->getContacts($Contacts['nextLink']);
?>

Search for Contacts

<?php
// Search for a single contact
$Contact = $ConstantContact->searchContactsByEmail('example@example.com');  

// Search for multiple contacts (up to 50)
$contacts = $ConstantContact->searchContactsByEmail(array('ex1@example.com', 'ex2@example.com'));
?>

Get contact details

<?php
// Search for a contact by Email Address
$search = $ConstantContact->searchContactsByEmail('example@example.com');

// Get details for the Contact
$Contact = $ConstantContact->getContactDetails($search[0]);
?>

Update a Contact

<?php  
// Search for a contact by Email Address
$search = $ConstantContact->searchContactsByEmail('example@example.com');

// Get details for the Contact
$Contact = $ConstantContact->getContactDetails($search[0]);

// modify Contact properties
$Contact->firstName = "John";
$Contact->lastName = "Doe";

//update the contact
$Contact = $ConstantContact->updateContact($Contact);
?>

###Delete a Contact

<?php
// Get a page of contacts
$contacts = $ConstantContact->getContacts();

// Delete the first contact returned
$delete = $ConstantContact->deleteContact($contacts['contacts'][0]);
?>