Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Python 3 Code to get List of All Users incl. User-Emails

Lucie Krennwallner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 2, 2019

HI,

please, can someone help me with Python 3 code to extract from Jira the list of all users and their email addresses?

 

Code used:

     import jira.client
     from jira.client import JIRA
     import urllib3

     urllib3.disable_warnings()

 

    jira = JIRA(options={'server':'https://jiraDOMAIN.com', 'verify':False}, basic_auth=   ('name','password#'))

 

    import requests
    import json

    url = "https://<jiraDomain<.com/rest/api/2/user/search?startAt=0&maxResults=1000"

    headers = {
    "Accept": "application/json",
    "Bearer": "access token"
    }

    response = requests.request(
    "GET",
    url,
    headers=headers,
    verify=False
    )

    print(....)

 

The result that's needed:

User       Email

name1   name1@email.com

name2   name2@email.com 

etc

 

Thanks for any help!

2 answers

0 votes
Michele Liberman July 18, 2023
# pip install atlassian-python-api
from atlassian import Confluence
hostname = "https://copco.atlassian.net"
user="cop@copco.com"
apikey="lolreally?"
confluence = Confluence(
     url=hostname,
     username=user,
     password=apikey,
     cloud=True)
users = confluence.get_all_members()
0 votes
Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2019

Hi @Lucie Krennwallner ,

I would recommend using this jira library.

Then you can loop through users in a certain group and print what you're looking for.

For example:

for user in jira.group_members("jira-administrators"):        
info
= jira.user(user)        
print(info.name, info.emailAddress)

or you can also loop through all groups 

Kamal Kailasa Babu May 29, 2020
for user in jira.group_members("jira-administrators"):  

the above will pull the user key

 info = jira.user(user)

the second will search for username,

 

and throiwng error if key and username is different

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events