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/count
like one has for the number of groups (i.e.,GET /{realm}/groups/count
).What you would need to do, is to define
max
query parameter to-1
so that you are sure to get all the members using the endpointGET /{realm}/groups/{id}/members
and then just count the number of members on thejson
response. 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.