# Adding user roles to users received from the management APIs

**URL:** <https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270>\
**Category:** Get Help\
**Tags:** management-api, roles\
**Created:** [April 6, 2023, 7:44pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270 "2023-04-06T19:44:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stehranchi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stehranchi/32/45581_2.png) [@stehranchi](https://community.auth0.com/u/stehranchi)\
**Post date:** [April 6, 2023, 7:44pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270/1 "2023-04-06T19:44:39Z")

</div>

Hi  
I would like to add the users’ roles to the user objects I receive from this management api:  
_[https://my-domain.us.auth0.com/api/v2/users](https://my-domain.us.auth0.com/api/v2/users)_  
I’ve tried both actions and rules to add “roles” to id and access tokens via custom claims. They are added successfully to these tokens, but this has no effect on the user object I receive from the above API.  
Is there a way to get roles as nested objects inside the user objects with a single request?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 6, 2023, 10:02pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270/3 "2023-04-06T22:02:51Z")

</div>

Hey there @stehranchi!

> [@stehranchi](#):
>
> I’ve tried both actions and rules to add “roles” to id and access tokens via custom claims. They are added successfully to these tokens, but this has no effect on the user object I receive from the above API.

The roles will need to be added directly to the user in order to be included in the user object. You can still achieve this in Action, but you’ll need to use the Management API from within the Action itself, please see:

[https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![stehranchi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stehranchi/32/45581_2.png) [@stehranchi](https://community.auth0.com/u/stehranchi)\
**Post date:** [April 7, 2023, 1:17pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270/4 "2023-04-07T13:17:28Z")

</div>

Thank you for your reply @ty.frith  
Not sure that I’m understanding it correctly.  
If I add the roles to the user’s meta-data in a post-login action, it means that after any changes in the user’s roles, these changes wont be applied to the user object, unless the user log into the system, am I right ?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [April 7, 2023, 4:30pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270/5 "2023-04-07T16:30:00Z")

</div>

Hey @stehranchi no problem, I’m happy to help!

> [@stehranchi](#):
>
> If I add the roles to the user’s meta-data in a post-login action, it means that after any changes in the user’s roles, these changes wont be applied to the user object, unless the user log into the system, am I right ?

Any change made to a user’s metadata (referring to metadata in [this context](https://auth0.com/docs/manage-users/user-accounts/metadata)) will be present in the user object/profile _but_ it would require the user to re-authenticate in order to update any tokens accordingly.

I misspoke previously in saying that roles added via the Management API are available at `/api/v2/users` - Any roles assigned directly to the user will need to be retrieved from `/api/v2/users/{id}/roles`

[https://auth0.com/docs/api/management/v2#!/Users/get\_user\_roles](https://auth0.com/docs/api/management/v2#!/Users/get_user_roles)

---

<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:** [April 25, 2023, 10:45pm UTC](https://community.auth0.com/t/adding-user-roles-to-users-received-from-the-management-apis/104270/6 "2023-04-25T22:45:27Z")

</div>

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