cancel
Showing results for 
Search instead for 
Did you mean: 

php getContactDetails, 'lists' array always empty

Highlighted
Occasional Contributor

php getContactDetails, 'lists' array always empty

Hello,

Every time i getContactDetails($email) and check the size of array 'lists', it is 0.

When i check it manually on the website, the contact is a part of many lists.

I have used var_dump and get: ["lists"]=> array(0) 

Or have done echo sizeof($m->lists); and always get 0.

 

I want to update a contact's lists but need their current lists to append to the new list.

I have tried it with many different email addresses and all variables return correctly except for the lists array.

Could someone check that this function is working correcly? 

Or let me know if there is some additional information i need to access this data?

Thanks

4 REPLIES 4
Highlighted
Moderator

Re: php getContactDetails, 'lists' array always empty

Hi Jason,

 

I think the issue might be coming from how you are using getContactDetails(). That function is expecting a contact ID, not a contact email address. I would suggest running the email through searchContactsByEmail() first, like this:

 

$search = $ConstantContact->searchContactsByEmail($email);

$Contact = $ConstantContact->getContactDetails($search[0]);

 If this is what you are doing, or if this doesn't help, please let us know!

Nick Galbraith
Support Engineer
Highlighted
Occasional Contributor

Re: php getContactDetails, 'lists' array always empty

Sorry for the mix up, I made a mistake when posting. 

I was using the $id=searchContactsByEmail($email), then using the returned contact to getContactByDetails($id[0]).

Still having the same problem though. Does the current version of the API return all the lists a contact is a part of normally? Reading other posts, it seems like its a feature possibly in beta testing?

Thank you.

Highlighted
CTCT Employee

Re: php getContactDetails, 'lists' array always empty

Hi,

 

What you are reporting is consistent with getting the contact by email, which doesn't return the lists the contact is on, or you could be creating a new array instead if adding new lists to the existing lists array for an existing customer.  See my code below that adds new lists to the existing array.

 

<?php

session_start ();
require_once 'ConstantContact.php';
require_once 'config.php';

$ConstantContact = new ConstantContact("oauth2", $apiKey, $username, $accessToken);

// 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
$emailAddress = "testemail11192012@test.com";

// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);

// If the search didnt return a contact object
if($search == false)
{
	// 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 ("Contact added.");

} // Otherwise we update our existing contact
else 
{
	// Gather data from our previous search and store it into a data type
	$contactObj = $ConstantContact->getContactDetails($search[0]);

	// We need to get the old array 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'][1]->id );
	 array_push($contactObj->lists, $lists['lists'][18]->id );
	
	// Update the contact and DONE
	$UpdateContact = $ConstantContact->updateContact($contactObj);
	echo ("Contact updated.");
}	


?>

 

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: php getContactDetails, 'lists' array always empty

Thanks that helped!