Bulk remove users from group in Jira

CST JIRA Confluence Admin April 26, 2017

In Jira, User Management > Groups > Bulk edit group members, remove many users in bulk from a group isn't possible. Instead, each user's id has to be selected by scrolling thru' the list of the group, then remove.

For many users such manual efforts doesn't seem to be practical, as its too cumbersome, much efforts involved.

While adding users works much better.

Is there a way to possibility to do this in easy steps or alternative ways ?

Any advise much appreciated.

2 answers

1 accepted

1 vote
Answer accepted
Daniel Friend 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(emailapi_token)

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

# Process the CSV file
with open(csv_file_pathmode='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
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 10, 2019

Hi @CST JIRA Confluence Admin 

My Approach is to create calls to the REST API

e.g.

curl -insecure -u admin:password -X DELETE -H "Content-Type: application/json" https://localhost:8080/rest/api/2/group/user?groupname=test&username=myussr

I usually keep an excel sheet with formulas to join user values and url snippets into useful REST calls and just paste them into a command window.

Crude but still saves me time.

Also check the marketplace for user management plugins.

Suggest an answer

Log in or Sign up to answer