I am using Keycloak API and I have a use case where I need to get the number of members in a group, before fetching all users.
Unfortunately, both endpoints GET /{realm}/groups/{id}/members and GET /{realm}/groups/{id} do not return such information.
The API doc on https://www.keycloak.org/docs-api/5.0/rest-api/index.html does not seem to indicate how we can get the count.
So, how we can get this information using the Keycloak API ?
Unfortunately, one does not have an endpoint like
GET /{realm}/groups/{id}/members/countlike one has for the number of groups (i.e.,GET /{realm}/groups/count).What you would need to do, is to define
maxquery parameter to-1so that you are sure to get all the members using the endpointGET /{realm}/groups/{id}/membersand then just count the number of members on thejsonresponse. Of course, this is a sub-optimal approach, but the only one using the API as it is.I have provided a complete script that automatizes this processes in the following repo.