How to Fetch Data from Jira in Python (original) (raw)
Jira is an agile project management tool developed by Atlassian, primarily used for tracking project bugs and issues. Over time, it has evolved into a work management platform capable of handling all stages of the agile methodology. There are two ways to get data from Jira:
- Using the Jira Python library.
- Using the Jira REST API.
Prerequisites in Jira
- Create a Jira user account.
- Create a domain, add a project and record some issues or bugs. We will fetch these issue details using Python.
- Obtain a valid API token from Atlassian API Tokens for authentication.

Issues recorded in JIRA tool for project "MedicineAppBugs"
**JQL: Jira Query Language (JQL) is an efficient way to fetch Jira data. One can filter issues, projects, or bugs using keywords and operators. JQL works with both the Jira library and REST API.
Fetch Data Using Jira Python Library
The jira library is an easy-to-use Python library to connect with Jira. It requires Python 3.5+.To install Jira Library use below command in command prompt or terminal:
pip install jira
**Example: Fetch All Issues from a Project
Python `
from jira import JIRA
jiraOptions = {'server': "https://yourdomain.atlassian.net/"} jira = JIRA(options=jiraOptions, basic_auth=("youremail@gmail.com", "your_api_token"))
for singleIssue in jira.search_issues(jql_str='project = MedicineAppBugs'): print('{}: {}: {}'.format(singleIssue.key, singleIssue.fields.summary, singleIssue.fields.reporter.displayName))
`
**Output

Issues data output using JIRA library.
**Explanation:
- jiraOptions = {'server': "https://yourdomain.atlassian.net/"}: Specifies your Jira domain.
- jira = JIRA(options=jiraOptions, basic_auth=(...)): Authenticates with Jira using your email and API token, and creates a Jira client instance.
- jira.search_issues(jql_str='project = MedicineAppBugs'): Fetches all issues from the project MedicineAppBugs using JQL.
- singleIssue.key: Unique identifier of the issue.
- singleIssue.fields.summary: Short description of the issue.
- singleIssue.fields.reporter.displayName: Name of the person who reported the issue.
**Example: Fetch a Single Issue
Python `
from jira import JIRA
jiraOptions = {'server': "https://yourdomain.atlassian.net/"} jira = JIRA(options=jiraOptions, basic_auth=("youremail@gmail.com", "your_api_token"))
singleIssue = jira.issue('MED-1') print('{}: {}: {}'.format(singleIssue.key, singleIssue.fields.summary, singleIssue.fields.reporter.displayName))
`
**Output

Details of one issue using the JIRA library
**Explanation: jira.issue('MED-1') Retrieves a single issue from Jira using its unique key (MED-1).
Fetch Data Using Jira REST API
The Jira platform provides a REST API that allows you to interact with Jira programmatically. Using the API, you can perform CRUD operations on issues, projects, dashboards, users, and more.
Here, we focus on fetching all issues for a specific project (MedicineAppBugs) using the REST API. This approach gives you full control over the data and allows you to filter, sort or process issues according to your requirements.
**Python Libraries Required
- json - built into Python
- requests - install with pip install requests
- pandas - install with pip install pandas
Getting the API URL
To fetch issues, we will use Jira’s Issue Search API.
- Go to the Jira Developer API.
- Navigate to Issue Search -> Search for issues using JQL (GET).
- The API endpoint is: GET /rest/api/2/search
- Append your Jira domain to form the full URL: https://your-domain.atlassian.net/rest/api/2/search
This URL allows you to retrieve all issues for your project or filter them using JQL queries.
Python `
import requests from requests.auth import HTTPBasicAuth import json import pandas as pd
url = "https://yourdomain.atlassian.net/rest/api/2/search" auth = HTTPBasicAuth("youremail@gmail.com", "your_api_token") headers = {"Accept": "application/json"} query = {'jql': 'project = MedicineAppBugs'}
response = requests.get(url, headers=headers, auth=auth, params=query)
dictProjectIssues = response.json() listAllIssues = []
def iterateDictIssues(oIssues, listInner): for key, values in oIssues.items(): if key == "fields": iterateDictIssues(values, listInner) elif key == "reporter": iterateDictIssues(values, listInner) elif key == "key": listInner.append(values) elif key == "summary": listInner.append(values) elif key == "displayName": listInner.append(values)
for key, value in dictProjectIssues.items(): if key == "issues": for eachIssue in value: listInner = [] iterateDictIssues(eachIssue, listInner) listAllIssues.append(listInner)
dfIssues = pd.DataFrame(listAllIssues, columns=["Key", "Summary", "Reporter"]) print(dfIssues)
`