# Accessing role IDs in rules

**URL:** <https://community.auth0.com/t/accessing-role-ids-in-rules/40025>\
**Category:** Get Help\
**Tags:** rules, management-api\
**Created:** [March 26, 2020, 9:27pm UTC](https://community.auth0.com/t/accessing-role-ids-in-rules/40025 "2020-03-26T21:27:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![auth0-admin1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/auth0-admin1/32/12732_2.png) [@auth0-admin1](https://community.auth0.com/u/auth0-admin1)\
**Post date:** [March 26, 2020, 9:27pm UTC](https://community.auth0.com/t/accessing-role-ids-in-rules/40025/1 "2020-03-26T21:27:15Z")

</div>

I’m trying to write a rule that will assign a role to a user upon login. I’ve worked through several of the different examples & community posts, but I cannot find a way to access the role ID’s programmatically in the hook function.

The ManagementClient access tokens that are available in the rule do not have `read:roles` permissions, so I can’t use the `getRoles()` method. Alternatively, I’ve seen a post for finding the role ID manually ([Assign Roles to users using Rules - #14 by dak2009](http://community.auth0.com/t/assign-roles-to-users-using-rules/27783/14)), but in our situation, we’re launching tenants on-demand via terraform, so we won’t have the ability to manually track and update these IDs.

Are there workarounds that I’m missing?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [March 31, 2020, 7:39pm UTC](https://community.auth0.com/t/accessing-role-ids-in-rules/40025/3 "2020-03-31T19:39:43Z")

</div>

Hi @auth0-admin1,

You should be able to register the hook as a M2M application and then request whatever scopes you want. This doc demonstrates how to do that:

> **[Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production)**
>
> Learn how to get Access Tokens to make scheduled frequent calls to the Management API.

Hope this helps,  
Dan

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 13, 2020, 10:16pm UTC](https://community.auth0.com/t/accessing-role-ids-in-rules/40025/4 "2020-07-13T22:16:07Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
