Getting e-mail addresses for Atlassian users
Asked by adam.aczel:

Hey there,

I would be super glad if someone could point me to the right direction. Here is my issue.

**Context:** I'm working on a project that involves integrating our internal applications with Atlassian's user management system. The primary goal is to retrieve email addresses of users from Atlassian to link them with other applications in our organization. To achieve this, I've been following the [Atlassian User Management API documentation](https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-manage/#api-users-account-id-manage-get).

**What I've Done So Far:**

1. **API Key and Setup:**

   * I created an API key from `admin.atlassian.com` under my organization's settings.
   * I've ensured that I have the necessary Organization ID and API key, as per the [documentation](https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/).
   * The API key is included in the Authorization header as a Bearer token.
2. **Request Attempt:**

   * I'm using the `/users/{account_id}/manage` endpoint to check user management permissions and eventually retrieve email addresses.
   * However, when I send a GET request to this endpoint, I consistently receive a `403 Forbidden` response.

**Issue:**

* **403 Forbidden Error:** Despite ensuring that the API key and Organization ID are correct, I'm still encountering a `403 Forbidden` error. This suggests that there might be a permissions issue, but I'm unsure how to proceed. Error mentions that Caller must be a ++verified org admin++. Does that mean there is a verification process to perform and a "simple" org admin does not suffice?

**My Questions:**

1. **Permissions:** Are there additional permissions or scopes that need to be configured for the API key to allow access to user email addresses?
2. **Organization and API Roles:** How can I verify that my API key and associated account have the appropriate roles to manage users and access their emails?
3. **Best Practices:** Is there a recommended approach or best practice for securely and efficiently accessing user emails through the Atlassian API?

**Additional Context:**

* My ultimate goal is to link Atlassian user emails with another application within our organization if there is a more straight forward way of doing this then please let me know.

Thank you for your assistance!


Answers:
author: Trudy Claspill
body: Hello [@adam_aczel](/t5/user/viewprofilepage/user-id/5566082)

Welcome to the Atlassian community.

Can you show us the actual code you are using? Use asterisks to replace sensitive data like the api token and account id.

comments: author: adam.aczel
body: Hello [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

Thanks for the welcome and getting back to me :)

I have set up calls to two different endpoints so far, tasks are executed by an Airflow DAG FYI.

1. Atlassian REST API v3 - Get all users [link](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-users/#api-rest-api-3-users-search-get) - status: works fine but e-mail is not returned
2. User management REST API v1 - Get profile [link](https://developer.atlassian.com/cloud/admin/user-management/rest/api-group-profile/#api-users-account-id-manage-profile-get) - status: returns 403

If emails were returned via the first endpoint I wouldn't even need the second one. Below I post the code excerpts for the respective endpoints, excluding logs and post processing for brevity.

1.  

```
def get_all_jira_users(email, token):

    url = "https://towa-digital.atlassian.net/rest/api/3/users/search"

    auth = HTTPBasicAuth(email, token)

    headers = {

    "Accept": "application/json"

    }

    all_users = []

    start_at = 0

    per_page = 100

    while True:

        params = {"startAt": start_at, "maxResults": per_page}

        response = requests.get(url, headers=headers, auth=auth, params=params)
```

2.  

```
def update_jira_users(account_id_list, token):

    base_url = "https://api.atlassian.com/users"

    headers = {

    "Authorization": f"Bearer {token}",

    "Accept": "application/json"    

    }

    user_data = []

    for account_id in account_id_list:

        url = f"{base_url}/{account_id}/manage/profile"

        response = requests.get(url, headers=headers)

        response.raise_for_status()

        user = response.json()

        user_data.append(user)

    return user_data
```

Thank you for your time!


author: adam.aczel
body: Hey [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)   

After a short break I'm back to this project. Is there a chance you could guide me to someone I should talk to regarding getting the e-mail addresses for our users in our space?

Thank you in advance!  
Adam


Tags: cloud

jira-cloud

organization-administration