Icontact api - get all contacts from list

608 Views Asked by At

I am using the icontact php api. I want to get the last contact who entered the list so in the icontact api php I have this:

<php
public function getContacts() {
    // Make the call and return the data
    return $this->makeCall("/a/{$this->setAccountId()} /c/{$this->setClientFolderId()}/contacts?listId=49626&status=total&createDate=2015-02-16&createDateSearchType=gt", 'GET');
}
?>

than I use this to call it:

<?php
$oiContact = iContactApi::getInstance();

try {

var_dump($oiContact->getContacts());

 } catch (Exception $oException) { // Catch any exceptions

var_dump($oiContact->getErrors());

 }

 $obj = $oiContact->getLastResponse();

 $data = json_decode($obj,TRUE);
  echo $data['contacts'][0]['email'];
  echo $data['contacts'][0]['commitmentscore'];
  echo $data['contacts'][0]['firstName'];
  echo $data['contacts'][0]['phone'];
  ?>

It keeps giving me the same contact it is because the 0 in the echo but how can I make that a variable or an if condition just not sure how

paste bins with full code

http://pastebin.com/SBf73UNb //call
http://pastebin.com/CuGcCvU1 //api

2

There are 2 best solutions below

1
On

I think you can use orderby option,

check this link

sample they used

Get all contacts on a list ordered by First Name    GET https://app.sandbox.icontact.com/icp/a/<accountId>/c/<clientFolderId>/contacts?orderby=firstName

Instead of firstname you can use date, something like normal SQL query doing then fetch only first contact.

Also the return data will be always array so you have to run within a foreach for iterate the data.

Hope it helps.

0
On

This worked

/contacts?listId=49626&orderby=createDate:desc&limit=1", 'GET');

Got it from this page

http://www.icontact.com/developerportal/documentation/advanced-users/