Auth0 Home Blog Docs

Retrieve users by role, sorted by name

I’m trying to retrieve all users in one particular role, sorted by their name. So far I’ve tried the roles api which allows getting pages of users by role but no sorting and the user search api which allows sorting by name but not filtering by role, as far as I can tell.

Any tips?

Hi @kirill.rakhman,

Welcome to the Auth0 Community Forum!

You will have to either sort the users from the GET /api/v2/roles/{id}/users endpoint, or add the roles as metadata and search and sort with GET/api/v2/users.

I would probably recommend the first method if your list of users with that role is manageable. The second method will take some scripting to edit the existing users metadata and will probably require more effort up front. The /users endpoint is also eventually consistent which can cause some problems.

Thanks,
Dan

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