Get a list of all users that don't have a role assigned

Hi All,
I can get a list of all the users in a role from the Management Api, but I would like a list of all users who don’t have a role.

Background. My app is strongly role driven so anyone registering cannot access any functionality without a role. This is fine as all users need to be approved and their role access will depend on their qualifications. So I need a list of users without a role (i.e. ones who are newly registered) to present to Admin for approval and manually updating.
We use a mix of database and social logins so I can’t user the post registration trigger.

Any way of doing this, or perhaps a better way…

Thanks

Hi @terry.cann,

Thanks for reaching out to the Auth0 Community!

Unfortunately, there is only the Get Role’s Users endpoint endpoint to call for the list of users that have a role. There isn’t an endpoint in the Management API that can get a list of users that are not assigned a Role.

As an alternative, you could consider appending the Roles to the user’s metadata so that you could filter them with Lucene search: q: user_metadata.roles:SOME_ROLE when using the List or Search users endpoint.

If not, there is the last option to get the list of users with the Get Roles’ Users endpoint and then filter for users not in the set with the List or Search users endpoint:
q: !(user_id:auth0|1234567890) && !(user_id:auth0|60987654321)

Please let me know if you have any questions.

Thank you.

1 Like

Hi @rueben.tiow

Thanks for clarifying that, and for the suggestions. The second suggestion is probably the approach I’ll need.

Thanks again.

1 Like