apigetresponse

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


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?


Solution

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