Bulk deleting users is a drastic step that should be performed in only the most dire circumstances. It’s not the nuclear option, but it’s close.
If you choose to do it anyway, that’s on you.
Here’s a little script for doing it in Jira Cloud:
def userName = "user@email.com"
def apiToken = "23423m46o9gnmsfsdfdfsdfsdfsdf"
def userIds = []
def inputString = "${userName}:${apiToken}"
def encodedString = Base64.encoder.encodeToString(inputString.bytes)
userIds.each{userId ->
//Get rid of the _ in "Delete" to confirm that you really truly want to do this
def getuser = dele_te("/rest/api/2/user?accountId=${userId}")
.header("Authorization", "Basic ${encodedString}")
.asObject(Map)
logger.warn(getuser.body.toString())
}
You’ll need a list of user IDs, an Atlassian account email, and a token. Read this post for more information about authenticating against the Atlassian Cloud API.
If you’re not sure how to get a list of user IDs, or how to get an API token, you probably shouldn’t be doing this.
What if you need to do this, but you don’t have ScriptRunner?
Here’s the Python equivalent:
import requests
import base64
username = "user@email.com"
api_token = "12354653gfdg3456345345"
cloud_url = "https://<instance name>.atlassian.net"
user_ids = []
input_string = f'{username}:{api_token}'
input_bytes = input_string.encode('utf-8')
encoded_bytes = base64.b64encode(input_bytes)
encoded_string = encoded_bytes.decode('utf-8')
headers = {
"Authorization" : f"Basic {encoded_string}"
}
for user_id in user_ids:
//Again, remove the _ if you're sure you want to do this
delete_user = requests.del_ete(f"{cloud_url}/rest/api/2/user?accountId={user_id}", headers=headers)
print(f"Attempted to delete user id {user_id}. Result:")
print(delete_user.status_code)
Leave a Reply