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:
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.
Hello. I’m new here and I’m trying to figure out how to do something very similar to this. The problem is, my response looks no different whether I GET
https://www.patreon.com/api/oauth2/v2/campaigns/<ID>/posts?fields[post]=url,title,content,published_at&sort[post]=-published_at
or
https://www.patreon.com/api/oauth2/v2/campaigns/<ID>/posts
I want to see those post fields, but they don’t show up. The documentation implies this is a scope problem, but it also says creator access tokens have all V2 scopes and I’m using that access token in my request. So the way I’m interpreting the documentation, I shouldn’t have to include any scope in my GET request? Am I misunderstanding the documentation?
Here’s the actual GET request:
https://www.patreon.com/api/oauth2/v2/campaigns/<ID>/posts?fields%5Bpost%5D%3Durl%2Ctitle%2Ccontent%2Cpublished_at%26sort%5Bpost%5D%3D-published_at
Thanks for any help you can provide.
You need to use cursor to page through the next set of posts. Check out how the WP plugin does it:
Ah, see that’s not the problem, I understand that.
What I’m talking about is the actual response data, not the pagination: it doesn’t have url,title,content, or published_at in it.
Here’s how each element looks:
{
"attributes": {},
"id": "11234962",
"type": "post"
},
How do I get each element to include url,title,content, and published_at?
This is my GET url: https://www.patreon.com/api/oauth2/v2/campaigns/<ID>/posts?fields%5Bpost%5D%3Durl%2Ctitle%2Ccontent%2Cpublished_at%26sort%5Bpost%5D%3D-published_at
Update: Apologies, but I figured out my issue: I was URL encoding the query string instead of just the brackets. Once I fixed that, they returned the content I expected.
maybe I’m wrong, but it looks like those parameters don’t do anything? At least the WordPress plug-in doesn’t acknowledge they exist. First it gets the post list, then it loops over each one and gets each individual post content one request at a time: patreon-wordpress/patreon_content_sync.php at b17ec94b1bb3b0c032e79bdd1561431e359c30ea · Patreon/patreon-wordpress · GitHub
I’m still confused about why @Eden4897 wrote that url that way. Did that have any effect for them?
After getting the posts list, you will need to get each post individually:
Hey @Eden4897, how exactly did you get this while loop to work? It seems I’ll have to build an async generator function to continually pull each cursor after the initial request to the API. Curious how this worked out for you.
Hi Shawn, looks like I’m a year late! I’ve recently had to do something similar, so I put together an article on how to get the rest of the results: https://blog.terresquall.com/2023/01/how-to-fix-the-patreon-api-only-returning-the-20-oldest-patrons/
Baiscally, when you get the results from the API query, if there are more results, there is a URL returned that you have to further query to get the next set of results.
Yes, to paginate your results, you need to use the page cursor. Increasing the page size can also help.