Assign user role depending on Tier

Hi,

After a user has logged in into my website, I would like to check if he is a patron and, in that case, check if he belongs to some Tier.
After that, depending on the tier, I would like to assign him a specific user role.

Since it is very difficult to test my code without a test account (I should pay to create a fake account to test my code), which is the correct code to achieve that purpose?

Many thanks in advance

Looks like a duplicate of this issue:

With regard to a test account, the Patreon docs address that here: https://docs.patreon.com/#faqs

Yeah, I ended up requesting the identity API endpoint, which gave me access to the user’s membership and tier information for just my campaign. I only needed to ask for the “identity” scope in the initial oauth request.

Here’s the code I used to build the API call. Note that this is JavaScript but it will show you what arguments to use if you are using a different language.

identityUrl = url.format({
        protocol: 'https',
        host: 'patreon.com',
        pathname: '/api/oauth2/v2/identity',
        query: {
            include: 'memberships.currently_entitled_tiers',
            'fields[user]': 'about,created,email,first_name,last_name',
            'fields[member]': 'patron_status,is_follower,full_name,email,pledge_relationship_start,lifetime_support_cents,currently_entitled_amount_cents,last_charge_date,last_charge_status,will_pay_amount_cents',
            'fields[tier]': 'description,title,amount_cents'
        }
    });

And obviously you’ll need to adjust the fields depending on what information you need. The docs are at least pretty helpful in that regard.

And yes, for testing I made a fake creator account in another browser and then backed it with my regular Patron user using a temporary debit card number (I use Privacy.com for this). But I also set my fake campaign to not charge backers so I shouldn’t ever get a charge to it. Good luck!

1 Like