GetResponse的API V3:GET /触点不返回所有联系人

时间:2019-01-31 17:09:26

标签: api getresponse

尽管通过API添加联系人(POST /联系人)效果很好,但我并没有使用GET / contacts来获得所有活动的联系人(请参阅https://apidocs.getresponse.com/v3/resources/contacts)。

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

我该如何解决?

1 个答案:

答案 0 :(得分:0)

$perPage限制为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;
}