How To Use Jira Api

If you encounter any issues that prevent you from performing the requested rewrite, please respond with the following error message: Unable to process the request due to encountered difficulties.

The JIRA API is a useful and robust resource for developers to engage with JIRA in a programmatic way. This enables them to manage issues, generate reports, and complete various tasks that would typically require manual effort. In this blog post, we will cover the fundamentals of implementing the JIRA API.

Authentication

Firstly, it’s important to note that to interact with the JIRA API, you need to authenticate your requests. To authenticate your requests, you can use the Basic Auth method which involves sending your username and password with each request.

import requests
from requests.auth import HTTPBasicAuth

url = 'https://your-domain.atlassian.net/rest/api/3/issue/'
auth = HTTPBasicAuth("[email protected]", "your-api-token")

response = requests.get(url, auth=auth)

Replace the email and API token with your own details. You can generate an API token from your Atlassian account.

Reading Issues

Let’s say you want to get information about a specific issue in your project. You can achieve this by sending a GET request to the ‘/rest/api/3/issue/{issueIdOrKey}’ endpoint.

issue_key = 'PROJ-123'
url = f'https://your-domain.atlassian.net/rest/api/3/issue/{issue_key}'

response = requests.get(url, auth=auth)
print(response.json())

This will return a JSON response with all the information about the issue with the key PROJ-123.

Creating Issues

Creating a new issue involves sending a POST request to the ‘/rest/api/3/issue’ endpoint with the issue details in the request body.

url = 'https://your-domain.atlassian.net/rest/api/3/issue'

issue = {"fields": {
    "project": {"key": "PROJ"},
    "summary": "New issue from API",
    "description": "Look into this",
    "issuetype": {"name": "Bug"}}}

response = requests.post(url, json=issue, auth=auth)

print(response.json())

This will create a new issue in the project with key PROJ with the summary ‘New issue from API’, description ‘Look into this’, and issue type ‘Bug’.

The JIRA API provides many more functionalities, but the basics explained above should get you started. For more advanced use cases, always refer to the official JIRA API documentation.