# Read roles for every user using auth0 SDK and not API

**URL:** <https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864>\
**Category:** Get Help\
**Tags:** user-search, user-management\
**Created:** [April 23, 2025, 8:09pm UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864 "2025-04-23T20:09:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathya.srinivasan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sathya.srinivasan/32/70889_2.png) [@sathya.srinivasan](https://community.auth0.com/u/sathya.srinivasan)\
**Post date:** [April 23, 2025, 8:09pm UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/1 "2025-04-23T20:09:54Z")

</div>

We have to read roles for every user using SDK. To read users using auth0 SDK from Nodejs the following statement works. users = await auth0.users.getAll(params); But users.getuserroles or readroles doesnt work.

We are using auth0 SDK and all the help are on auth0 API. What is the method name to read roles associated with users using SDK?

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [April 23, 2025, 8:34pm UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/3 "2025-04-23T20:34:50Z")

</div>

Hi @sathya.srinivasan,

Welcome to the Auth0 Community and thank you for your post!

In order order to retrieve the users roles using the pre-build methods of the NodeJs SDK, instead of trying “users.getuserroles” you can use the “ **users.getRoles** ” function. You can check out more about this from the NodeJs documentation on [GetRoles](https://auth0.github.io/node-auth0/classes/management.UsersManager.html#getRoles) from inside the **UsersManager** property.

I hope this helps!  
Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![sathya.srinivasan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sathya.srinivasan/32/70889_2.png) [@sathya.srinivasan](https://community.auth0.com/u/sathya.srinivasan)\
**Post date:** [April 24, 2025, 12:44am UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/4 "2025-04-24T00:44:55Z")

</div>

Ty for your quick response. “message”: “{"message":"user.getRoles is not a function"}” . I tried and doesnt work. Do you have an example of a working code for auth0 SDK to get roles for a user? Thanks again!

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [April 24, 2025, 6:46pm UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/5 "2025-04-24T18:46:41Z")

</div>

Hi @sathya.srinivasan,

Essentially this would be the nodejs code presented in the [GET /api/v2/users/{id}/roles](https://auth0.com/docs/api/management/v2/users/get-user-roles) endpoint as well.

```auto
import { ManagementClient } from 'auth0';

const management = new ManagementClient({
  client_id: <APPLICATION_CLIENT_ID>,
  client_secret: <APPLICATION_CLIENT_SECRET>,
  domain: <APPLICATION_DOMAIN>
});

const result = await management.users.getRoles({ id: userId });

```

You could also put this in a try and catch block for a better structure.

Hope this helps and if you have further questions, feel free to ask!  
Kind regards,  
Remus

---

<div class="post-metadata">

**Author:** ![sathya.srinivasan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sathya.srinivasan/32/70889_2.png) [@sathya.srinivasan](https://community.auth0.com/u/sathya.srinivasan)\
**Post date:** [April 28, 2025, 4:30am UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/6 "2025-04-28T04:30:01Z")

</div>

Thank you so much Remus! That worked. Appreciate your prompt response & help.

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [April 28, 2025, 3:32pm UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/7 "2025-04-28T15:32:46Z")

</div>

You’re more than welcome @sathya.srinivasan,

I’m glad this helped!  
Best wishes,  
Remus

---

<div class="post-metadata">

**Author:** ![sathya.srinivasan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sathya.srinivasan/32/70889_2.png) [@sathya.srinivasan](https://community.auth0.com/u/sathya.srinivasan)\
**Post date:** [April 29, 2025, 2:44am UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/8 "2025-04-29T02:44:39Z")

</div>

Hi @remus.ivan

I notice the error below when i read 50 users (only 17 users exist in lower environment). Please help me understand the rate limits in different environments.  
For every user, roles call is made.  
Error ManagementApiError: Global limit has been reached  
at UsersManager.parseError (file:///var/task/node\_modules/auth0/dist/esm/management/management-client.js:29:16)  
at process.processTicksAndRejections (node:internal/process/task\_queues:95:5)  
at async UsersManager.request (file:///var/task/node\_modules/auth0/dist/esm/lib/runtime.js:102:23)  
at async UsersManager.getRoles (file:///var/task/node\_modules/auth0/dist/esm/management/\_\_generated/managers/users-manager.js:359:26)  
at async file:///var/task/readUser.mjs:254:23  
at async Promise.all (index 6)  
at async Runtime.readUsers (file:///var/task/readUser.mjs:252:28) {  
errorCode: ‘too\_many\_requests’,  
error: ‘Too Many Requests’,  
statusCode: 429,  
body: ‘{“statusCode”:429,“error”:“Too Many Requests”,“message”:“Global limit has been reached”,“errorCode”:“too\_many\_requests”}’,  
headers: Headers {  
date: ‘Tue, 29 Apr 2025 01:00:17 GMT’,  
‘content-type’: ‘application/json; charset=utf-8’,  
‘content-length’: ‘120’,  
connection: ‘keep-alive’,  
‘cf-ray’: ‘937adc936a92b298-PDX’,  
‘cf-cache-status’: ‘DYNAMIC’,  
‘retry-after’: ‘1’,  
‘cache-control’: ‘no-cache’,  
‘strict-transport-security’: ‘max-age=31536000; includeSubDomains’,  
vary: ‘origin, Accept-Encoding’,  
‘access-control-expose-headers’: ‘WWW-Authenticate,Server-Authorization’,  
‘x-auth0-l’: ‘0.008’,  
‘x-content-type-options’: ‘nosniff’,  
‘x-ratelimit-limit’: ‘10’,  
‘x-ratelimit-remaining’: ‘0’,  
‘x-ratelimit-reset’: ‘1745888419’,  
server: ‘cloudflare’,  
‘alt-svc’: ‘h3=“:443”; ma=86400’  
},  
msg: ‘Global limit has been reached’  
}

Thanks in advance!

---

<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:** [May 13, 2025, 2:45am UTC](https://community.auth0.com/t/read-roles-for-every-user-using-auth0-sdk-and-not-api/185864/9 "2025-05-13T02:45:02Z")

</div>

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