When calling getContacts inside for loop gives exception, if it is outside loop (for example update a particular contact ) it is working without any error. I am using V2 API. Below is my code: $contacts = $cc->contactService->getContacts($params['token']);
$allCustomers = $db->getAllCustomerFromDB();
for($i=0;$i<count($allCustomers);$i++){
$exist=0;
for($j=0;$j<count($contacts->results);$j++){
if($contacts->results[$j]->email_addresses[0]->email_address==$allCustomers[$i]['email']){
$exist=1;
}
}
$contactItem = $cc->contactService->getContacts($params['token'], array("email" => $allCustomers[$i]['email'])); // this makes exception (line number:117)
if($exist==1){
if(!empty($contactItem->results)){
$contact = $contactItem->results[0];
if ($contact instanceof Contact) {
$contact->addList('20');
$contact->first_name = $allCustomers[$i]['first_name'];
$contact->last_name = $allCustomers[$i]['last_name'];
$cStat = $cc->contactService->updateContact($params['token'], $contact);
}
}
}else{
$contact = new Contact();
$contact->addEmail($allCustomers[$i]['email']);
$contact->addList('10');
$contact->first_name = $allCustomers[$i]['first_name'];
$contact->last_name = $allCustomers[$i]['last_name'];
$cStat = $cc->contactService->addContact($params['token'], $contact);
}
} The error I got is : stdClass Object ( [response] => [exception] => stdClass Object ( [xdebug_message] => ( ! ) Ctct\Exceptions\CtctException: Forbidden in F:\websites\cc\src\Ctct\Services\BaseService.php on line 78 Call Stack #TimeMemoryFunctionLocation 10.0014415832{main}( )...\cc_v2.php:0 29.66032289384Ctct\Services\ContactService->getContacts( )...\cc_v2.php:117 ) )
... View more