6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
Search...
How to request JIRA API with Python examples
John D K
Sep 22, 2018 • 2 min read
Jira API is simple and powerful but you may have difficulties using it with google account. You
will find many solutions on the web most of which nor working anymore as deprecated. In this
article you will find information how to run requests against the API in 2018 using python for
public and private projects(google account and atlassian accounts).
Request JIRA API with module jira
Your first option to request information and update the JIRA API is by using module jira. It can
be installed by:
pip install jira
and used by:
# This script shows how to use the client in anonymous mode
# against jira.atlassian.com.
from jira import JIRA
import re
# By default, the client will connect to a JIRA instance started from the
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassi
# Override this with the options parameter.
options = {
'server': 'https://jira.atlassian.com'}
jira = JIRA(options)
# Get all projects viewable by anonymous users.
projects = jira.projects()
# Sort available project keys, then return the second, third, and fourth k
By using SoftHints - Python,
keys = sorted([project.key forLinux, Pandasin
project , you agree to our Cookie Policy.
projects])[2:5]
print(keys)Accept
i
https://blog.softhints.com/request-jira-api-with-python-examples/ 1/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
# Get an issue.
issue = jira.issue('JRA-1330')
print(issue)
# Find all comments made by Atlassians on this issue.
atl_comments = [comment for comment in issue.fields.comment.comments
if re.search(r'@atlassian.com$', comment.author.emailAddre
print(atl_comments)
result:
['BAMJ', 'BLOGIT', 'BON']
JRASERVER-1330
[]
As you can see this code is working for public projects.
More information about module JIRA:
JIRA API Documentation
Python JIRA Library is the easiest way to automate JIRA
I wasn't able to log into private project with google accound by using jira module. But using
direct request and JIRA access token I was able to request information. It's visible in the next
section.
Request JIRA API with requests
If you want to request information from private projects you can with google account then you
can try second option which is:
import requests
r = requests.get('https://myproject.atlassian.net/rest/api/2/search?jql=pr
for k in response.json().keys():
#print(k)
#print(response.json()[k])
By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
if k == 'fields':
print(response.json()[k]['issuetype'])
Accept
print(response.json()[k]['description'])
print(response json()[k]['lastViewed'])
https://blog.softhints.com/request-jira-api-with-python-examples/ 2/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
print(response.json()[k][ lastViewed ])
print(r.json())
where:
myproject - is your subdomain of JIRA
myuser@mydomain.com - is your mail or gmail account
your_token_access_key - your private access token. In order to get access token you need to
visit: Manage your Atlassian account - login and request a token. How to work with JIRA
access tokens: Atlassian API tokens
Note: JIRA API authentication with password is not working in 2018 as password is deprecated.
More information below: Basic auth for REST APIs:
Using passwords with Jira REST API basic authentication
Support for passwords in REST API basic authentication is deprecated and
will be removed in the future. While the Jira REST API currently accepts your
Atlassian account password in basic auth requests, we strongly recommend
that you use API tokens instead. We expect that support for passwords will
be deprecated in the future and advise that all new integrations be created
with API tokens.
If you have problems accessing the API with code you can try to get this URL in the browser
while you are loged in your JIRA account:
https://myproject.atlassian.net/rest/api/latest/issue/MY_ISSUE_KEY?expand=names,renderedFields
For more information about the API you can visit this links:
JIRA Server platform REST API reference
Jira Cloud REST API
Advanced Tutorials
By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
How to Execute aAccept
String Containing Code in Python
In this quick tutorial, we'll show how to execute string
https://blog.softhints.com/request-jira-api-with-python-examples/ 3/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
John D K
Apr 11, 2022 • 2 min read
How to Search and Replace in Excel File using Python
Do you need to search and replace a list of
John D K
Jun 2, 2020 • 3 min read
By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
Request JIRA API with module jira
Request JIRA API withAccept
requests
https://blog.softhints.com/request-jira-api-with-python-examples/ 4/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
Help Us
Powered by Ghost
By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
Accept
https://blog.softhints.com/request-jira-api-with-python-examples/ 5/5