The origin story of this blog post is that I was helping my friend who works as a music teacher and performer bring her offerings online, and I thought it would be helpful to include links to her Patreon Reward tiers to make it easier for her clients to contribute to her music. However, as I began to dig in and try to unravel the mystery that is the Patreon API, I found some myself running into many 404 errors using the npm helper package and constantly banging my head against a wall of "do I really not know how to read these API docs?!?!?!".
So here's what I was trying to accomplish:
All I wanted was the campaign tiers exposed on her Patreon page. I already set up a client in the Patreon Portal, grabbed the create access token (so I could skip OAuth, my nemisis), and grabbed the current user campaigns using the npm helper.
const patreonAPIClient = patreonAPI(access_token)
patreonAPIClient('/current_user/campaigns')
Now that I had the campaign ID of the only campaign she had, I could hardcode that in (as she isn't planning on hosting another) and use that to retrieve campaign specific information. So according to the docs, you look at the campaign endpoint and pass in the ID:
const patreonAPIClient = patreonAPI(access_token)
patreonAPIClient('/campaigns/${id}')
And this will give you the campaign info. However it returns a 404 and I really started questioning my ability to work with and understand the API Documentation.
Well after some digging, turns out I am not crazy and there is an issue in how the helper package API url is constructed. I plunged into their github src code and found that AHA the npm package exports the base path as "api/oauth2/api", but the campaign endpoint does not live there. If you look at the API Docs for Campaigns, you'll see that the base path should be "api/oauth2/v2" So if you try to access "/campaigns/${id}", you get a 404 with this npm package because "api/oauth2/api/campaigns" does not exist.
For now, it seems that the best work around would be to use a fetch or other http request instead. It appears the V1 of campaigns is also working, so here are the 2 ways I found to access a specific campaign:
- via the v2
https://www.patreon.com/api/oauth2/v2/campaigns/5136507
- via the v1
https://www.patreon.com/api/campaigns/5136507
The key difference I have found between these 2 is that v2 includes no fields by default and requires Authorization, and v1 includes all fields and relationships without need to authorize.
As a note, Patreon's API docs do mention that they are not actively maintaining the API due to resource constraints.
Top comments (0)