Patreon v2 /campaigns/<ID>/posts only returns 20 OLDEST posts

I am sending GET to https://www.patreon.com/api/oauth2/v2/campaigns/<ID>/posts?fields[post]=url,title,content,published_at&sort[post]=-published_at. It only returns 20 posts, and the annoying part is that it is returning the oldest 20 posts. Is there any way to make it return all posts, or to return the newest 20 posts? Thank you.

This question is also relevant for me, did you find any ways to sort or walk through pages?

Yes, you have to get the cursor and request the next batch. Patreon WordPress does it. You can check its example here:

1 Like

Thank you for the comment and sorry for the late reply. I have tried POSTing to https://www.patreon.com/api/oauth2/v2/campaigns/${CAMPAIGN_ID}/posts?fields[post]=url,title,content,published_at&page[count]=2 and https://www.patreon.com/api/oauth2/v2/campaigns/${CAMPAIGN_ID}/posts?fields[post]=url,title,content,published_at&page[count]=1000, yet it always still returns only 20 posts. The solution I have landed on is to send POST requests to the links.next url again and again until there is no link provided in the responce.

Here is the relevant code in NodeJs for anyone in need


const axios = require('axios');
axios.defaults.headers.common['Authorization'] = `Bearer ${ACCESS_TOKEN}`;

let posts = [];
let url = encodeURI(
  `https://www.patreon.com/api/oauth2/v2/campaigns/${CAMPAIGN_ID}/posts?fields[post]=url,title,content,published_at`
);
while (true) {
  const res = await axios.get(url);
  posts.push(...pagePosts);
  if (!res.data.links?.next) break;
  url = res.data.links.next;
}

Yeah. That’s the way to do it. The next cursor.