Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve Epic details from Jira using Python, you can follow the below process:

  1. Import the necessary modules - requests and json.
  2. Set the Jira URL and the Jira API token.
  3. Define the endpoint URL for retrieving the Epic details in Jira.
  4. Define the JQL (Jira Query Language) to retrieve the Epic details.
  5. Set the headers and the parameters.
  6. Send a GET request to the endpoint URL using the requests module.
  7. Parse the response JSON data using the json module.
  8. Extract the required Epic details from the JSON data.
  9. Finally, print the retrieved Epic details.

Here is a sample code snippet that demonstrates the above process:

import requests
import json

# Set the Jira URL and the Jira API token
JIRA_URL = 'https://your-jira-domain.atlassian.net/rest/api/3'
JIRA_API_TOKEN = 'your-jira-api-token'

# Define the endpoint URL for retrieving the Epic details in Jira
ENDPOINT_URL = JIRA_URL + '/search'

# Define the JQL (Jira Query Language) to retrieve the Epic details
JQL = 'issuetype=Epic'

# Set the headers and the parameters
headers = {
  "Accept": "application/json",
  "Content-Type": "application/json"
}

params = {
  "jql": JQL,
  "fields": "key,summary"
}

# Send a GET request to the endpoint URL using the requests module
response = requests.get(ENDPOINT_URL, params=params, auth=("username", JIRA_API_TOKEN), headers=headers)

# Parse the response JSON data using the json module
json_data = json.loads(response.text)

# Extract the required Epic details from the JSON data
for issue in json_data['issues']:
  print("Key:", issue['key'], "Summary:", issue['fields']['summary'])

Note that you need to replace the JIRAURL, JIRAAPI_TOKEN, and the 'username' placeholder in the authentication with your actual Jira URL, Jira API token, and Jira username respectively. Also, you can specify the required fields in the params variable to retrieve additional details of the Epics.