# Assign user role depending on Tier

**URL:** <https://www.patreondevelopers.com/t/assign-user-role-depending-on-tier/3154>\
**Category:** Uncategorized\
**Created:** [May 16, 2020, 6:33am UTC](https://www.patreondevelopers.com/t/assign-user-role-depending-on-tier/3154 "2020-05-16T06:33:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pietrolc](https://avatars.discourse-cdn.com/v4/letter/p/bbce88/32.png) [@pietrolc](https://www.patreondevelopers.com/u/pietrolc)\
**Post date:** [May 16, 2020, 6:33am UTC](https://www.patreondevelopers.com/t/assign-user-role-depending-on-tier/3154/1 "2020-05-16T06:33:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sffc](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/sffc/32/1284_2.png) [@sffc](https://www.patreondevelopers.com/u/sffc)\
**Post date:** [May 17, 2020, 5:51pm UTC](https://www.patreondevelopers.com/t/assign-user-role-depending-on-tier/3154/2 "2020-05-17T17:51:11Z")

</div>

Looks like a duplicate of this issue:

> [@Website Features for Certain Tier Members](https://www.patreondevelopers.com/t/website-features-for-certain-tier-members/3081/8):
>
> I had to sign up for an account to say thanks for posting this question! I was struggling to build something similar - a way to query the active tier for the authorized user for the campaign I know about. I only wanted to use the ‘identity’ scope so as not to request too much access. It was working fine to just give me their membership to my campaign but I could not figure out how to get the tier from there - I kept getting access denied. I never would have thought to include memberships.current…

With regard to a test account, the Patreon docs address that here: [API Reference](https://docs.patreon.com/#faqs)

---

<div class="post-metadata">

**Author:** ![mekane](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/mekane/32/1297_2.png) [@mekane](https://www.patreondevelopers.com/u/mekane)\
**Post date:** [May 18, 2020, 12:59am UTC](https://www.patreondevelopers.com/t/assign-user-role-depending-on-tier/3154/3 "2020-05-18T00:59:57Z")

</div>

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](http://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!
