Forum Discussion

ADS_PSI's avatar
ADS_PSI
Mentor
7 years ago

Is there api to get deatils of all users with certain role?

Hi,

I am searching for API which lists down all users with a certain role.

Thanks.

 

3 Replies

  • ADS_PSI,

    You can use below API to get all users from the role (eg. "Administrator") you add in name.

     

    SELECT * FROM users WHERE roles.name='Administrator'

     

  • luk's avatar
    luk
    Boss
    7 years ago

    ADS_PSI yes, although the answer you found uses API v1 while Parshant's solution uses v2, which is recommended and gives you the option to only fetch the information you actually need (OK, not if you use the SELECT * FROM =)...but it gives you far greater control over the response and is generally a bit faster than v1.

    Small addition, if you need to aggregate users having multiple roles, you can do:

    SELECT id FROM users WHERE roles.name IN ('Administrator', 'Moderator')

    This would require you to do multiple API calls with your v1 solution...