I am attempting to retrieve JSON data from the JIRA API and am utilizing the JIRA package for Python, which works well for obtaining information about projects and issues. However, I’m unsure how to extract JSON from a specific endpoint, such as:
/jira/rest/structure/1.0/structure.json
Below is my server-side implementation:
from jira.client import JIRA
jira_config = {'server': 'https://bits.example.com/jira'}
try:
jira_connection = JIRA(options=jira_config,
basic_auth=('username', 'password'))
project_info = jira_connection.project('CTT')
print(project_info)
print(project_info.lead.displayName)
except Exception as error:
print(error.args[0])
print('Connection to JIRA failed')
hey! You might wanna try using jira_connection._session.get() to query specific endpoints directly. It’s “advanced usage” tho, so be careful with the error handling and headers needed. Best of luck!!
hey, also ensure your jira instance is configured to allow API requests to that specific endpoint. Some plugins or customizations might need their own permissions, so double-check those to avoid unexpected issues.
To fetch data from a specific endpoint like the structure endpoint you mentioned, you can use the API methods available in requests coupled with your jira_connection. Make sure that you understand the required authentication details. Here’s a practical example:
import requests
url = 'https://bits.example.com/jira/rest/structure/1.0/structure.json'
headers = {'Content-Type': 'application/json'}
auth = ('username', 'password')
response = requests.get(url, headers=headers, auth=auth)
if response.ok:
data = response.json()
print(data)
else:
print('Error:', response.status_code)
print('Response:', response.text)
Make sure to replace your username and password with environment variables or some secure method. This method gives you more control over the request and allows you to customize it as per your needs.