Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete bulk users from a group in Confluence cloud

Darshil Kothari February 8, 2023

How to delete bulk users from a group in Confluence cloud

3 answers

0 votes
Daniel Friend
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 12, 2023

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.


#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}'")
0 votes
Amelie Winkler _Appfire_
Atlassian Partner
February 9, 2023

Hi @Darshil Kothari – 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

Darshil Kothari February 9, 2023

Hi Amelie,

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

Amelie Winkler _Appfire_
Atlassian Partner
February 20, 2023

Hi @Darshil Kothari - 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.

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

0 votes
Ashish Bijlwan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2023

Hi @Darshil Kothari 

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:

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 to know more about the add-in.

 

Kindly let me know if this helps you.

 

Thank you,
Ashish 

Darshil Kothari February 9, 2023

Thanks for your message ! Will surely give it a try. 

Evn Tomeny [Appfire]
Atlassian Partner
February 13, 2023

Just a note @Darshil Kothari - 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!

Like Akbar likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events