JIRA - python get projects and their leads displayName using projects()

Tejvir Singh July 9, 2018

I want to reduce the api calls to JIRA. so I want to get the list of projects using projects() method in Jira-python api. But I am only getting the key and the name of the projects. Any way I can get the lead's displayName using this method only? 

 

I don't want to use the project(id) every time I need the displayName. 

 

 

1 answer

0 votes
Mo Eb January 24, 2023

Hi - Any luck with this? Im struggling with the same I can extract name key and id but not leads descriptions etc.

Thanks 

Tejvir Singh January 24, 2023

Hi Moses, Yes I was able to run the following code to get the information. 

You can add the following to the URL: 

https://Jira-instance.com/rest/api/2/project/?expand=lead"

This would give you the lead information. You can do description as well. 

Let me know if you need more help.

Thanks

Tejvir Singh 

Mo Eb January 24, 2023

Thanks for your prompt response Tejvir,

Yes, thats the api I can call to get the information. But Im keen to get and process it with Python script. I was able to get projects with jira.projects() and filter through it and get name key and id but not any progress with extracting leaders

Thanks

Tejvir Singh January 24, 2023
Following is the python code snippet I have been using, 
if 'session_logged_in_user' in session:
headers = {'cookie':session['session_logged_in_user'],'Content-Type': 'application/json',
'Accept': 'application/json'}
request_status_code, result = request_obj.get_request(url=PROJECTS_URL, headers=headers)

if request_status_code == 444:
print(" JIRA is responding slow. ")
return redirect(url_for("login",message = " Response from JIRA is slow. Please try again in 2 minutes. "))

if request_status_code == 414:
print(" There is a connection Error ")
return redirect(url_for("login",message = " Connectivity issue with JIRA. Please try again later. "))

# project_list will hold all the records from JIRA into local variable
# Step 3: Loop through the project list, if any new project(s) is added or removed
if len(all_projects_in_JIRA) != len(result) or not all_projects_in_JIRA:

for p in result:
if p['key'] not in all_projects_in_JIRA:
all_projects_in_JIRA[p['key']] = []
all_projects_in_JIRA[p['key']].append(p['name'])
all_projects_in_JIRA[p['key']].append(p['lead']['displayName'])
all_projects_in_JIRA[p['key']].append(p['avatarUrls']['16x16'])
all_projects_in_JIRA[p['key']].append('T')
#print(" Printing all the keys", all_projects_in_JIRA.keys())
print("Projects list is received/updated. ")
Hope this helps.
Mo Eb January 24, 2023

Thank you very much Tejvir, This was really helpful :) got me up and running

Cheers

Suggest an answer

Log in or Sign up to answer