Forums

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

how to fetch issues with specific label using JIRA API

peter April 4, 2022

Hi There,

 I am trying to fetch all the issue keys of a specific project using JIRA python api and below is the code. For example, Can i please know how to fetch the issue keys with a specific label called "server".

 

url = "https://abcd.com/rest/api/2/search?maxResults=4" 
auth = HTTPBasicAuth("cred, "password)


headers={
"Accept": "application/json",
"Content-Type": "application/json"
}

query = {
'jql': 'project = APACHE'
}

projectIssues = []
response=requests.get(url,headers=headers,params=query,auth=auth)
data=response.json()
issues=data["issues"]
for issue in issues:
projectIssues.append(issue["key"])

Thank you

1 answer

0 votes
Trudy Claspill
Community Champion
April 4, 2022

Hello @peter 

Welcome to the community.

Modify your jql query to be

'project = APACHE AND labels in ("server")'

That should get all issues from the APACHE project where "server" is one of the values in the Labels field. If you want to get issues where "server" is the only value in the Labels field then use this

'project = APACHE AND labels = "server" '
peter April 5, 2022

Thank you for the reply. I have tried the above mentioned solutions but however, issues are not getting filtered based on the labels, they are being filtered based on "maxresult=4"

Trudy Claspill
Community Champion
April 5, 2022

@peter 

What documentation are you referencing for this api? Can you provide a link?

peter April 5, 2022

hi @Trudy Claspill  

 

What i mean to say is that when i added the labels in the code, it is not generating the issue keys based on labels instead it is provides first four issue keys based on maxResults=4

I am using the below documentation:

 

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-fields/#api-group-issue-fields

 

 

url = "https://abcd.com/rest/api/2/search?maxResults=4" 
auth = HTTPBasicAuth("cred, "password)


headers={
"Accept": "application/json",
"Content-Type": "application/json"
}

query = {
'jql': 'project = APACHE AND labels = "server'
}

projectIssues = []
response=requests.get(url,headers=headers,params=query,auth=auth)
data=response.json()
issues=data["issues"]
for issue in issues:
projectIssues.append(issue["key"])
Trudy Claspill
Community Champion
April 5, 2022

I see I partially misunderstood your initial problem statement. I thought you were trying to use the Python Jira API. You are actually using the JIRA REST API in python code.

The correct link for the JIRA REST API documentation for the issue search function is:

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-get

Can you provide the full response you are getting? I don't recall exactly where, but I believe somewhere in there will be the full URL that actually got submitted. I suspect that the JQL query is not getting properly appended.

I would also suggest removing the ?maxResults=4 in your first line to see if that makes a difference. Are you intentionally trying to limit the results to just the first 4 items returned?

Suggest an answer

Log in or Sign up to answer