Paginating in Constant Contact API

Some services of Constant Contact API return only a subset of results and you’re supposed to submit additional requests with a “next” parameter to fetch more. The implementation isn’t exactly straight forward though, and for some reason, CtCt doesn’t provide any pagination code sample. So here it is, for getContactsFromList().

You can either use ListService directly, or through an overarching ConstantContact object. Note that the $limit parameter will actually return $limit + 1 contacts. The max value of 500 will yield 501 contacts.

with ConstantContact object

  1. /** @var Contact[] $contacts */

ListService directly

  1. span class=”st0″>’limit’‘?’), $params);
  2. }
  3.  

3 Responses to “Paginating in Constant Contact API”

  1. Hi Petra,

    I write the API docs for the CTCT v2 API. I’m wondering if you would allow me to use your code samples in our documentation, with due credit provided?

    Thanks,
    Rich

  2. Oh absolutely. I’m glad that you want to improve the documentation. Let me know if I can help.

  3. Matt L. says:

    Your w/CC object code is just a bit off. With the APIv2 php wrapper, simply setting the $param = $result->next; is incorrect and results in an exception. What’s really expected there is either an integer or a bit of a URL query string, so you need to do this:

    $param = “?next=” . $result->next;

    so the param looks like that bit of a query string. Just passing in the next variable from the response isn’t quite enough.

    Thanks.

Leave a Reply