Skip to content

Patreon API

Created: 2020-02-18 19:16:13 -0800 Modified: 2020-02-20 09:36:15 -0800

  • At the time of writing (February 19th, 2020), there is no sandbox or testing environment (reference). Patreon officially suggests that you pledge to a fake account and then cancel before you get charged.
  • You can find your clients and API keys here on Patreon
  • Register a new client on Patreon
    • My goal was not to have a “Log in with Patreon” button, so I filled in a bogus redirect URI (but still from a domain that I control).
    • After creating the client, I got a “Creator’s Access Token” which I could use as the bearer token.
  • I got campaign data with this cURL command:

curl —request GET \

—url https://www.patreon.com/api/oauth2/api/current_user \

—header ‘authorization: Bearer TOKEN_GOES_HERE’

  • The response had data.relationships.campaign.data.id, which I needed for the next step:

curl —request GET \

—url https://www.patreon.com/api/oauth2/api/campaigns/CAMPAIGN_ID_FROM_LAST_STEP/pledges?include=patron.null \

—header ‘Authorization: Bearer TOKEN_GOES_HERE’

  • The response had included[0].attributes.social_connections.discord.user_id
    • Note that the index of 0 was just to show that this is an array.
  • There’s also links.next which contains a link of the next set of pledges in case you have so many that it has to paginate. The issue is that this gets returned even when your API call already returned the full dataset, so it’s not obvious when you need to ask for more data. I’ll probably end up just checking to see if I got the same patrons more than once.
  • Tokens expire every 31 days, then you need to use your refresh token to get new access and refresh tokens (and save those). Here’s a cURL command I got working based on this.

curl —location —request POST ‘https://www.patreon.com/api/oauth2/token’ \

—header ‘Content-Type: application/x-www-form-urlencoded’ \

—data-urlencode ‘grant_type=refresh_token’ \

—data-urlencode ‘client_id=CLIENT_ID_HERE’ \

—data-urlencode ‘client_secret=CLIENT_SECRET_HERE’ \

—data-urlencode ‘refresh_token=REFRES_TOKEN_HERE’

Using the NodeJS API with proper OAuth

Section titled Using the NodeJS API with proper OAuth

They have examples/server.js:

  • When you register your OAuth client on Patreon, make sure to set the redirect URI to http://localhost:5000/oauth/redirect. You could also edit an existing client to include that information.
  • Run “npm” or “yarn” in the root and in the examples folder, and run the “build” script in the root.
  • Run the “start” script in the examples folder
  • Navigate to http://localhost:5000, click “log in”, allow the app, and you’ll see an API call to fetch your campaigns.

Apparently jsonapi-datastore, which is internal to the patreon module, is the problem.