Getting a PHP invalid argument error on a for each loop related to the ListService Method


Getting a PHP invalid argument error on a for each loop related to the ListService Method

Warning: Invalid argument supplied for foreach() in C:\wamp\www\websites\blum_center_for_health\development\wordpress\wp-content\themes\blankslate\classes\Ctct\Services\ListService.php on line 30


I have tested my Key and token on your site and can retrieve data fine from there. When I am on my machine the list array appears to be empty.


I am developing on my local machine:



Apache 2.4.4

PHP 5.4.12



Michael Meehan

Hi Michael,


Sorry to hear about the trouble. Is your ListService file similar to the one here? I have a foreach loop on line 31 in the original V2 PHP SDK file.


In your script, are you trying to use the getLists method and passing in only the access token as a parameter? I'd be happy to take a look at a code snippet of what you're trying to do--can you send a snippet that shows how you set your access token and make a call to the method you're trying to use to


Thanks in advance.


Best Regards,

Shannon Wallace

Partner API Support Engineer

require_once 'src/Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;

ini_set("error_reporting", E_ALL);
ini_set("display_errors", 1);

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "my api key is here");
define("ACCESS_TOKEN", "my token is here");
$cc = new ConstantContact(APIKEY);

$lists = $cc->getLists(ACCESS_TOKEN);



if (isset($_REQUEST['email']) && strlen($_REQUEST['email']) > 1) {
$action = "Getting Contact By Email Address";
try {
$response = $cc->getContactByEmail(ACCESS_TOKEN, $_REQUEST['email']);
if (empty($response->results)) {
$action = "Creating Contact";
$contact = new Contact();
$contact->first_name = $_REQUEST['first_name'];
$contact->last_name = $_REQUEST['last_name'];
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact, true);
// update the existing contact if address already existed
} else {
$action = "Updating Contact";
$contact = $response->results[0];
$contact->first_name = $_REQUEST['first_name'];
$contact->last_name = $_REQUEST['last_name'];
* The third parameter of updateContact defaults to false, but if this were set to true it would tell
* Constant Contact that this action is being performed by the contact themselves, and gives the ability to
* opt contacts back in and trigger Welcome/Change-of-interest emails.
* See:
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, true);

// catch any exceptions thrown during the process and print the errors to screen
} catch (CtctException $ex) {
echo json_encode(array("msage"=>$rseultsu));






Hi @user95575,


This was most likely related to an issue that we have located and corrected. If you are still experiencing the error please let us know.

Jimmy D.
Tier II API Support Engineer
Developer Portal

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

Visit Page