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 csvimport 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
https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-lifecycle/#api-users-account-id-manage-lifecycle-delete-post
Hi again, thank you for the answerI'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 okaythe 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 timewhich 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 need to use the Admin API keys to execute this API.
You can create one by following the steps in the below mentioned document:
https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/
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"}
It looks like you're new here. Sign in or register to get started.