How to delete bulk users from a group in Confluence cloud
Asked by Darshil Kothari:

How to delete bulk users from a group in Confluence cloud


Answers:
author: Daniel Friend
body: I had a few issues with this and getting it to work. I ended up reaching out to Atlassian for assistance.  
The below Python script worked a treat for Jira and confluence.  
First export the users from the cloud environment (Be sure to select "All users", "Group Membership" and "Pivot to Column'), then filter and create a separate CSV file of all the users and the groups that you wish to remove them from.  

<br />

#Remove Users From Group  
import requests  
from requests.auth import HTTPBasicAuth  
import json  
import csv

# Jira Cloud URL  
jira_url = '<https://your-site.atlassian.net>' # Update to your cloud site URL

# API endpoint for adding users to a group  
api_endpoint = f"{jira_url}/rest/api/3/group/user"

# Authentication credentials  
email = 'accountEmail' # Update to your user ie example@user.com  
api_token = 'apiToken' # Update to the API key associated with the user

# Read the CSV file with user and group IDs  
csv_file_path = 'users_and_groups.csv' # If your filename is different, update it here

auth = HTTPBasicAuth(email, api_token)

headers = {  
"Accept": "application/json",  
"Content-Type": "application/json"  
}

# Process the CSV file  
with open(csv_file_path, mode='r') as csv_file:  
csv_reader = csv.DictReader(csv_file)  
for row in csv_reader:  
user_id = row\['User id'\] # Change to match your CSV column names  
group_id = row\['Group id'\] # Change to match your CSV column names

# Skip if user_id is empty  
if not user_id:  
print(f"Skipping deletion for user with empty ID in group with ID '{group_id}'.")  
continue

# Set the query parameters for the group id and account id  
query = {"groupId": group_id,  
"accountId": user_id}

# Make the API request to add the user to the group  
response = requests.delete(  
api_endpoint,  
headers=headers,  
params=query,  
auth=auth  
)

if response.status_code == 200:  
print(f"Deleted user with ID '{user_id}' from group with ID '{group_id}'.")  
else:  
print(f"Failed to delete user with ID '{user_id}' from group. Status Code: '{response.status_code}'. Additional information: '{response.text}'")


author: Amelie Winkler _Appfire_
body: Hi [@Darshil Kothari](/t5/user/viewprofilepage/user-id/5142526) -- Amelie from the Appfire team here. As Ashish mentioned, unfortunately, it's impossible to bulk-delete users via Confluence natively.

You could try the Confluence CLI app, which allows you to delete users in bulk. Let me know if you want to try it out, and I'm happy to pull together the steps!

Cheers, Amelie

comments: author: Darshil Kothari
body: Hi Amelie,

Sure, thanks. Could you please share the steps, would like to try that too?


author: Amelie Winkler _Appfire_
body: Hi [@Darshil Kothari](/t5/user/viewprofilepage/user-id/5142526) - what you would want to do is, run a command like this:

-a runFromUserList --common "--action removeUserFromGroup --userId @userId@ --group Developers"

Here you're removing users from the so-called "Developer" group.

To refine the set of users in the list, you would use --field parameters as described in the [documentation](https://appfire.atlassian.net/wiki/spaces/CSOAP/pages/68458059/runFromUserList).

Alternatively, if you have a CSV or other external source of the users that need to be deleted, you could leverage the runFrom action for that data source (e.g., runFromCSV). The rest should be pretty much the same.

Let me know if it worked!

Cheers,

Amelie


author: Ashish Bijlwan
body: Hi [@Darshil Kothari](/t5/user/viewprofilepage/user-id/5142526)

Welcome to Atlassian Community!

Unfortunately, Jira/Confluence Cloud doesn't have the feature to bulk delete users from the instance or from a specific user group.

For this a feature to implement for Jira Cloud is already raised <https://jira.atlassian.com/browse/JRACLOUD-8047>

As a workaround, you can create a script using the [REST API endpoint to Delete users](https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&utm_medium=302#api-rest-api-3-user-delete):

```
DELETE /rest/api/3/user
```

Also, you can use a free third party add-in to bulk delete users. Please refer [https://confluence.atlassian.com/cloudkb/remove-multiple-users-from-your-atlassian-cloud-site-1155467985.html#:\~:text=Go%20to%20Atlassian%20Admin%20page,that%20need%20to%20be%20deleted](https://confluence.atlassian.com/cloudkb/remove-multiple-users-from-your-atlassian-cloud-site-1155467985.html#:~:text=Go%20to%20Atlassian%20Admin%20page,that%20need%20to%20be%20deleted) to know more about the add-in.

Kindly let me know if this helps you.

Thank you,  
Ashish

comments: author: Darshil Kothari
body: Thanks for your message ! Will surely give it a try.


author: Evn Tomeny _Appfire_
body: Just a note [@Darshil Kothari](/t5/user/viewprofilepage/user-id/5142526) - it sounded like you wanted to remove users from a group. Be careful with the "DELETE /rest/api/3/user" command that Ashish suggested, as it will delete the user completely, and not simply remove them from a group. If you want to use the Rest API to remove users from a Group without Deleting them, you should use:

```
DELETE /rest/api/3/group/user
```

Good luck!


Tags: cloud

confluence-cloud