-1

Although adding contacts via the API (POST /contacts) works fine, i don't get all active Contacts using GET /contacts (see https://apidocs.getresponse.com/v3/resources/contacts).

public function getContacts()
{
    return $this->get('contacts', [
        'query' => [
            'campaignId' => $this->campaign
        ],
        'fields' => 'name,email',
        'perPage' => $this->perPage
    ]);
}

How can i fix it?

Fred 2019
  • 1
  • 3
  • Hey, as GR's docs say, API returns items page by page, by default — 100 items per page. You can get 1000 maximum, but anyway you'll need to iterate through all the pages to get all the contacts. – a-change Feb 04 '19 at 14:56
  • 1
    Thanks. Yes, the 1000 maximum, is what i hadn't thought of. – Fred 2019 Feb 05 '19 at 16:56

1 Answers1

0

$perPage is limited to 1000:

public function getContacts($page = 1)
{
    return $this->get('contacts', [
        'query' => [
            'campaignId' => $this->campaign
        ],
        'fields' => 'name,email',
        'sort' => [
            'createdOn' => 'desc'
        ],
        'perPage' => $this->perPage, // max. 1000
        'page' => $page
    ]);
}

public function getAllContacts()
{
    $page = 1;
    $allContacts = [];
    while ($contacts = $this->getContacts($page++)) {
        array_push($allContacts, ...$contacts);
    }
    return $allContacts;
}
Fred 2019
  • 1
  • 3