Check if user is subscribed to campaign w/o login?

Hi folks, I’m working on a game that allows folks to subscribe in game or via patreon for similar perks. Previously, I had used Discord as it seemed like the easiest way to ensure a user was who they said they were, and give them perks in game via a role. This worked, but honestly the Discord integration is a bit shaky at times, and can be a bit frustrating.

Thus, I was hoping that there was a way I could get an API key or something from a client, have them paste it, and then query the API to check if they’re subscribed to my specific campaign. I really want to avoid “login with patreon” as the extra oauth bits are more of a pain than they’re worth in my experience (from other oauth providers, not specifically patreon). Is there a way this can be done?

client

If by client you mean your user, thats a bigger hassle?

I really want to avoid “login with patreon

PHP lib and WP plugin have excellent and smooth implementation of login/oauth. You can just copy the code logic there and sort it out easily. If you are using PHP you can even directly plug it in. (Or use the lib as an api to do auth).

Yes, I do mean user. API keys are a workflow that I can teach if it were possible (go here, copy this, put it in here), but logging in requires a lot more oauth hassle on my part, and it requires me to keep it updated if something changes, etc. I really don’t want to be beholden to an oauth provider if they decide to change their flow. In my experience, services that work with API keys generally keep their scopes the same and/or add new ones as needed, but for example, I’ve had the same Guild Wars 2 API key since the game launched and honestly that’s kinda what I was looking for here.

Also, I’m using nodejs, I’ve seen that there is a library (https://github.com/simov/grant) that can make it slightly better, but I really just wanted to avoid oauth if possible. It sounds like that won’t be possible, so I’ll see if there are any alternatives I can explore - maybe I can link a user by having them put in their patreon email and I can check my campaign via API or something.

This api is Patreon’s api so it should be ok to use it with Patreon functionality as far as i can see.

Basically the information you seek - patron status - wont be obtainable without you having an access token to which user has given permission to acquire that information.

Having user to put in an email to have your app access your creator account via creator token and checking that email’s patron status may work, but its easily spoof-able.

Could you walk me through how I would build a list of emails subscribed to my campaign programmatically?

It is easily spoofable, but this is a low-throughput situation where I can handle spoofs with a unique constraint in the database + manually sorting out people who might try to spoof someone elses email.

First you create a client for your app at:

The app will also have your creator access and refresh tokens.

Using that creator token, you call the api for your campaign and get its details and members. Using example calls from WP plugin and PHP lib would help for this.

You iterate through list of members and process their emails. I recommend not saving the email if the email is not marked as verified.

Thanks a bunch, that’ll be a great start!

1 Like

I’m having a bit of trouble here, trying to figure out how to get these all in one API call. What I have so far is this:

    const params = new URLSearchParams({
      include: 'patron.null',
      'page[count]': '999'
    });
    const res = await fetch(`https://www.patreon.com/api/oauth2/api/campaigns/<campaignid>/pledges?${params}`, {

      headers: {
        Authorization: `Bearer ${process.env.PATREON_ACCESS_TOKEN}`
      }

    });

I’ve tried doing any number of things but I can’t seem to merge them all in to one response. I don’t want to do one API call just to do X more API calls to get all of my users emails. Is that the only way to do it?

I looked at the PHP library but it’s been a while since I did PHP, so I’m not sure how to make heads or tails of what it’s doing there.

Bump. I’m still not sure how I would get a list of emails with my access token. I can see the emails in my Relationship Manager on Patreon, so I would think I can query Patreon to get that list live but I’m still stumped.

Turns out I was querying the wrong endpoint. Querying here seems to give me what I want: https://www.patreon.com/api/members?include=user&fields[member]=pledge_amount_cents,pledge_relationship_start,lifetime_support_cents,patron_status,email,campaign_lifetime_support_cents,discord_vanity&fields[user]=full_name&fields[pledge]=amount_cents,currency,cadence&filter[membership_type]=active_patron&filter[campaign_id]=142446&sort=&page[offset]=0&page[count]=999

Will have to validate that I can still get it working with an API key but a quick test shows this is the endpoint/data I want.

[edit] Looks like this doesn’t work from curl/nodejs, but does work in my browser. Back to square one on this I guess.

1 Like

You must make sure you are sending user agent header while making calls. Otherwise you may be mistaken for a bot.

Is there any chance you could help me come up with a sample cURL that would display this info? I tried passing the token as Authorization: Bearer but I kept getting a 401, I need to be logged in. Here’s my cURL:

curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36' -H 'Authorization: Bearer <creator access token>' https://www.patreon.com/api/members?include=user&fields[member]=pledge_amount_cents,pledge_relationship_start,lifetime_support_cents,patron_status,email,discord_vanity&fields[user]=full_name&fields[pledge]=amount_cents,currency,cadence&filter[membership_type]=active_patron&filter[campaign_id]=<my campaign id>&sort=&page[offset]=0&page[count]=999

Here’s the specific response I’m getting: {"errors":[{"code":53,"code_name":"LoginRequired","detail":"This route is restricted to logged in users.","id":"df129dad-a59d-4542-a827-859b72c43944","status":"401","title":"This route is restricted to logged in users."}]}

/api/members is not the endpoint which you can get any info. Check out the available routes here:

https://docs.patreon.com/#apiv2-resource-endpoints

Okay, but that link actually gives me the info I need, it looks like I need a cookie set for it to work though.

Can you help me with a sample query that does work?

Try including identity as a relationship and specifically requesting the email from identity while you are requesting a page of members.

Again, I reiterate: how do I do that? I have no idea how to make that association. Now I’m trying to query for any data on the user object and it’s not giving me any data:

    const params = new URLSearchParams({
      include: 'user',
      'fields[user]': 'full_name',
      'page[count]': '999'
    });

The endpoint I’m trying to hit is this one now: https://www.patreon.com/api/oauth2/v2/campaigns/<my campaign id>/members

The full url would be https://www.patreon.com/api/oauth2/v2/campaigns/<my campaign id>/members?include=user&fields[user]=full_name&page[count]=999

I’ve tried just getting the full name since that should theoretically show up, but it doesn’t. But according to their docs, it should have that property. So I have no idea what’s going on here.

Just check this code out:

It requests identity resource, but it also requests membership which is a relationship of identity. And it requests currently_entitled_tiers, and campaign info from membership resource.

Basically that - you can try including another resource as a relationship like this, and then asking specific fields from that resource.

But of course, the return will depend on whether you have the right scopes/permissions to get those fields. That depends on your token.

Okay, so if you look at my last post, you’ll see that I already tried that. The only endpoint that seems to make sense is campaigns/id/members. That’s what I’ve been trying to query. Here’s what it says in the docs: Top-level includes: address (requires campaigns.members.address scope), campaign, currently_entitled_tiers, user. You can see my query in my previous post.

Can you please provide me with an actual working query? As previously stated I’ve tried multiple ways of getting this data, and clearly there is something I’m missing.

To start with: Do you have a token which has campaigns.members scope for the campaign you are trying to access?

I assume so, I don’t know how to get specific permissions from the client: image

I’ve been passing in my creator access token from that page.