Hello, I want to clean up my groups in Confluence. How do I see the number of users in the groups without having to select them one by one? Thanks
I am not aware of any way to obtain this info from the front end. However, you can query the database directly e.g for users in crowd directory --select /count (*) /distinct from CWD\_MEMBERSHIP where GROUP_NAME= <> and check the groups from CWD\_GROUP would be a nice place to start.
CWD\_MEMBERSHIP where GROUP_NAME= <> and check the groups from CWD\_GROUP would be a nice place to start.
An alternative method is to use the Confluence REST API with jq, for example:
curl -s -n \ -H "Accept: application/json" \ 'https://myconfluence.server/rest/api/group/nexus-users/member'| jq -r .size
However... there is a limit of 200 results by default, so for groups with more than 200 users, you will need something a little more elaborate that uses the pagination feature.
Here's a shell script I knocked together that copes with groups containing any number of users:
#!/usr/bin/env bashgroupname=$1total=0result=$(curl -s -n \ -H "Accept: application/json" \ "https://myconfluence.server/rest/api/group/${groupname}/member")size=$(echo $result | jq -r '.size')total=$((total+$size))next_set=$(echo $result | jq -r ._links.next)base=$(echo $result | jq -r ._links.base)while [[ $next_set != "null" ]]do result=$(curl -s -n -H "Accept: application/json" "${base}${next_set}") size=$(echo $result | jq -r '.size') total=$((total+$size)) echo running total: $total # this is optional next_set=$(echo $result | jq -r ._links.next)doneecho Total members in $groupname is: $total
which when called, looks something like this:
➜ ./count_group_members.sh my-test-grouprunning total: 400running total: 600running total: 800running total: 1000Total members in my-test-group is: 1008
If using Atlassian Crowd as the backend auth server, you can find the number of users in a group with the following Crowd REST API call:
curl -s -n \ -H "Accept: application/json" \ 'https://mycrowd.server/crowd/rest/usermanagement/1/group/user/direct?groupname=my-test-group&max-results=10000' | jq -r '.users[].name' | wc -l
If the result comes out at exactly the same as max-results, increase max-results until it doesn't.
It looks like you're new here. Sign in or register to get started.