Retrieving groups of users



  • I need to retrieve all users that are (examples) employees or residents via API. In the docs I've found that I can for example create such roles and assign users the according role. Or, I can create such groups and make users members of the according group. Yet I'm still scratching my head on how to exactly retrieve those users. I've found that using Elasticsearch (using the User Search APIs) I can create a query that retrieves the users. Is there maybe a simpler way that I'm missing? E.g. in https://fusionauth.io/docs/v1/tech/core-concepts/groups it says "Once a User is a member of a Group they may be identified as a member of the Group and retrieved using the Group APIs.", but I've not found how I can retrieve that user using the the Group APIs. Pointers highly appreciated, thanks



  • If you use the search in the UI and open the ‘Advanced’ search controls you can search by group or application role. If you then click Show Elasticsearch query you’ll see how we are performing this search query.

    Using the API (as long as you are using the elasticsearch search engine) you can utilize the Elasticsearch Query String Query DSL, or a full JSON search query object.

    Example, to query by group membership where the group Id is 8e9225f9-6286-4bbb-9d4b-f75228018386, you'd use a queryString of:

    memberships.groupId:8e9225f9-6286-4bbb-9d4b-f75228018386
    

    The groups API doc you reference is incorrect; we'll need to fix that.




Log in to reply