There are several users that must be deleted. I must create a script to delete all of them.
I search for the documentation's solutions but they don't work.
curl --request DELETE \ --url 'https://api.atlassian.com/admin/v1/orgs/{orgId}/directory/users/{accountId}' \ --header 'Authorization: Bearer <access_token>'
as well generated the script
import csv
import requests
url_template = "https://api.atlassian.com/admin/v1/orgs/{orgId}/directory/users/d{account_id}"
def delete_user(url, access_token):
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.delete(url, headers=headers)
if response.status_code == 204:
print(f"User with account ID {account_id} deleted successfully.")
else:
print(f"Failed to delete user with account ID {account_id}. Status code: {response.status_code}")
access_token = input("Enter your access token: ")
org_id = input("Enter your organization ID: ")
csv_file = input("Enter the path to the CSV file: ")
with open(csv_file, "r") as file:
reader = csv.reader(file)
for row in reader:
account_id = row[0]
url = url_template.format(orgId=org_id, account_id=account_id)
delete_user(url,access_token)
Hi Petik,
If the user accounts are all managed accounts then you should be able to delete these users in bulk using the below user management API
Hi again, thank you for the answer
I've checked that POST request.
curl --request POST \ --url 'https://api.atlassian.com/users/{account_id}/manage/lifecycle/delete' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'
i did filled the account_id, it's okay
the part with the access_token. I entered 2 different tokens:
1 is from atlassian account > security > Create and manage API tokens
2 is from the place where it gives me the organization id and the token at the same time
which of them should have been valid, bcs after the using each of them it says that i am not authorized.
so the question is , which token/key must be used? And during the call is it important to use the call with the device where the creator account is logged ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Petik,
You need to use the Admin API keys to execute this API.
You can create one by following the steps in the below mentioned document:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I do have those values , but when use that POST request, it says that i am not authorized..
after that POST request, it says
{"code":401,"message":"Unauthorized"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Petik,
If you are using the right Admin API keys, you should not have any issues when trying to delete a user.
The only use case I can think of is when the user is provisioned from the IDP; in this case, you will not be allowed to delete the user.
If you can share any other details then it will be helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Will it make a problem, if I don't have atlassian admin. I have only api key?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
there are users that are local and made with IDP , but none of them are deleted. I just don't know why it gives 401 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.