0% found this document useful (0 votes)
13 views5 pages

JIRA API Requests with Python Guide

This document provides guidance on how to use the JIRA API with Python, including examples for both public and private projects. It discusses using the 'jira' module for anonymous access and the 'requests' library for accessing private projects with an API token. The document also highlights the deprecation of password authentication and recommends using API tokens for security.

Uploaded by

Pawan kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

JIRA API Requests with Python Guide

This document provides guidance on how to use the JIRA API with Python, including examples for both public and private projects. It discusses using the 'jira' module for anonymous access and the 'requests' library for accessing private projects with an API token. The document also highlights the deprecation of password authentication and recommends using API tokens for security.

Uploaded by

Pawan kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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 [Link].
from jira import JIRA
import re

# By default, the client will connect to a JIRA instance started from the
# (see [Link]
# Override this with the options parameter.
options = {
'server': '[Link]
jira = JIRA(options)

# Get all projects viewable by anonymous users.


projects = [Link]()

# Sort available project keys, then return the second, third, and fourth k
By using SoftHints - Python,
keys = sorted([[Link] forLinux, Pandasin
project , you agree to our Cookie Policy.
projects])[2:5]

print(keys)Accept

i
[Link] 1/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
# Get an issue.
issue = [Link]('JRA-1330')
print(issue)

# Find all comments made by Atlassians on this issue.


atl_comments = [comment for comment in [Link]
if [Link](r'@[Link]$', [Link]
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 = [Link]('[Link]

for k in [Link]().keys():
#print(k)
#print([Link]()[k])
By using SoftHints - Python, Linux, Pandas , you agree to our Cookie Policy.
if k == 'fields':

print([Link]()[k]['issuetype'])
Accept
print([Link]()[k]['description'])
print(response json()[k]['lastViewed'])
[Link] 2/5
6/26/22, 8:55 PM How to request JIRA API with Python examples - Softhints
print([Link]()[k][ lastViewed ])

print([Link]())

where:

myproject - is your subdomain of JIRA


myuser@[Link] - 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:

[Link]

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

[Link] 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

[Link] 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

[Link] 5/5

Common questions

Powered by AI

Developers might face challenges such as deprecated methods (e.g., password-based authentication) and compatibility issues with accounts linked through providers like Google. Resources to overcome these include using API tokens for authentication and referring to JIRA's comprehensive REST API documentation which provides guidance on supported authentication mechanisms and example requests .

To integrate API tokens into a Python script for secure interaction with the JIRA API, a developer should obtain the token from their Atlassian account and use it in the authorization header of HTTP requests. Using the 'requests' library, the token can be passed as a bearer token within the authorization headers, providing secure access without embedding password information in the script, thus maintaining confidentiality and security .

For automating tasks related to JIRA, the 'jira' Python module is recommended. It provides an easy-to-use interface to interact with JIRA's API, allowing operations such as querying projects and issues. While the 'requests' module paired with API tokens provides similar functionality with more control over HTTP requests, the 'jira' module simplifies these tasks by abstracting some of the complexity inherent in raw HTTP operations and providing direct support for JIRA-centric operations .

To obtain an API token for accessing private projects in JIRA, visit Manage your Atlassian account, log in, and request a token. This token can then be used in HTTP requests to authenticate access to private project data, replacing the deprecated password method in API requests .

Issue details for a specific JIRA ticket can be retrieved using the 'jira' module with Python by calling the 'issue' method with the ticket ID. Additional information such as comments by Atlassian employees can be extracted by filtering the comments field in the response for specific email addresses .

API tokens are preferred over passwords for JIRA API authentication due to enhanced security. Passwords are deprecated and will be removed in future updates, increasing the risk of integration failures. API tokens provide a secure and reliable way to authenticate requests, negating the risk associated with sending plain text passwords over the network .

Using the 'jira' library for accessing private JIRA projects has limitations when a Google account is involved, as logging into private projects using this library may not work reliably. An alternative method is to use API tokens with direct HTTP requests to overcome these limitations and access private project data securely .

Password-based authentication poses significant security risks, such as the potential for credentials to be exposed in transit or through log access. API tokens mitigate these risks by acting as a secure token equivalent to securely transmitting a secret key embedded in the application, reducing the attack surface by eliminating plain text credential submissions. The transition to API tokens is part of securing API interactions in line with modern security practices .

The recommended method for authenticating requests to the JIRA API is using API tokens. Password-based authentication is deprecated as of 2018. API tokens offer a more secure method to interact with the REST API, as Atlassian has deprecated passwords and encourages using API tokens instead .

To access the JIRA API for public projects using Python, the 'jira' module can be utilized in anonymous mode. This can be achieved by installing the 'jira' library, setting the server option to 'https://jira.atlassian.com', and then creating a JIRA instance using these options to retrieve public project data .

You might also like