Fetch pagination

I use fetch_page_of_members_from_campaign() in the PHP library.

In this function, we have:

$url = "campaigns/{$campaign_id}/members?page%5Bsize%5D={$page_size}";

But when I set the size to move than 500, then it takes endless of time to get the data (more than 5 minutes). My question is, how can I set size to 100 and then paginate through the pages? Meaning separate the fetching into multiple calls.

For example:

Request one gets 1-100 entries. Request two gets 101-200 entries. Do you get what I mean?

I am certain there is a way to paginate it? Does the API docs offer a solution?

API Reference Is what you’re looking for.

Your $url would end uplooking something like: campaigns/{$campaign_id}/members?page%5Bcount%5D={$page_size}&sort=pledge_relationship_start&page%5Bcursor%5D={$start_date} which would return the members of your campaign in ascending order with the oldest member on or after the start date first. You will want to urlencode($start_date) before building that url, as well.

Since the PHP Patreon package is a bit iffy on what it supports (page size vs page count, for instance), you’ll probably want to bypass fetch_page_of_members_from_campaign and just pass the URL suffix to get_data directly.

1 Like