This tutorial will help you to:
Users with emails whose domain is claimed can still be found in Managed accounts under Directory even after being removed.
To complete this tutorial, you need the following:
API token ≠ API key:
AccountId is a required path parameter to remove user access.
An API token is needed to get the accountId in the next step. Use an API token to authenticate your script.

To create an API token:
To get the accountId:
Use the Jira User Search API with the API token and Basic authentication to get the accountId: GET /rest/api/3/users/search
1 2curl --request GET \ --url 'https://your-domain.atlassian.net/rest/api/3/users/search' \ --user 'email@example.com:<api_token>' \ --header 'Accept: application/json'
Search the results by email address or name to find the correct accountId.
Learn more about the Jira API.
If you don’t have Jira, export a .csv of the user list. Learn how to export users from a site
The Remove user access script uses an API key as a Bearer access token. It also uses the Organization ID field as a path parameter.

To create an API key and get the Organization ID:
Learn more about the API keys.
The v2 APIs are directory-aware, so you need a directoryId as a path parameter. Use the API key and Organization ID with the Get directories endpoint to get the directoryId: GET /admin/v2/orgs/{orgId}/directories
1 2curl --request GET \ --url 'https://api.atlassian.com/admin/v2/orgs/{orgId}/directories' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'
Search the results to find the correct directoryId.
Learn more about the Get directories API.
Use the accountId, directoryId, API key and Organization ID from the previous steps to remove user access: DELETE /admin/v2/orgs/{orgId}/directories/{directoryId}/users/{accountId}
1 2curl --request DELETE \ --url 'https://api.atlassian.com/admin/v2/orgs/{orgId}/directories/{directoryId}/users/{accountId}' \ --header 'Authorization: Bearer <access_token>'
Make your first request and get started with the Remove user from directory API and get more information on error codes.
Rate this page: