GetResponse API v3: GET /contacts does not return all contacts

482 Views Asked by At

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?

1

There are 1 best solutions below

0
Fred 2019 On BEST ANSWER

$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;
}