I am currently using the JIRA Python API to generate JIRA issues automatically from an Excel sheet. My existing code is functioning well with basic fields, but I’m encountering issues when I try to include both the Epic Link and Affected Versions in the issues.
Here’s the code I have:
from jira import JIRA
import pandas as pd
user_email = '[email protected]'
api_token = 'your_api_token_here'
api_url = 'https://yourcompany.atlassian.net'
jira_options = {'server': api_url}
jira_instance = JIRA(jira_options, basic_auth=(user_email, api_token))
issues_data = []
data_from_excel = pd.read_excel(r'tickets_data.xlsx')
for row_index in data_from_excel.index:
issue_fields = {}
issue_fields['project'] = {'key': 'PROJECT_KEY'}
issue_fields['summary'] = data_from_excel['Ticket Summary'][row_index]
issue_fields['description'] = data_from_excel['Ticket Description'][row_index]
issue_fields['issuetype'] = {'name': 'Task'}
issue_fields['priority'] = {'name': data_from_excel['Priority'][row_index]}
issue_fields['labels'] = [data_from_excel['Labels'][row_index]]
issue_fields['reporter'] = {'name': data_from_excel['Reporter'][row_index]}
issue_fields['assignee'] = {'name': data_from_excel['Assignee'][row_index]}
new_issue = jira_instance.create_issue(fields=issue_fields)
print(new_issue.key)
I’m struggling to correctly set the Epic Link and Affected Versions in the issue_fields, and they don’t appear in the created tickets. Has anyone had success with this while programmatically creating JIRA issues?
Been wrestling with this exact problem for months in my automation scripts. The breakthrough was realizing epic links aren’t regular fields - they’re custom fields that reference the epic’s issue key directly. I had to dig through our JIRA config to find the right custom field identifier. What finally worked was this helper function that grabs the epic link field ID dynamically: epic_field = next(f['id'] for f in jira_instance.fields() if 'epic' in f['name'].lower())
. Then just use that field ID when creating issues. For affected versions, make sure the version objects actually exist in your project first - otherwise you’ll get cryptic API errors that don’t tell you the version wasn’t found.
epic links are tricky - you’ve got to use the actual epic key, not the name. try issue_fields['customfield_10014'] = 'EPIC-123'
(though that custom field number changes depending on your instance). for affected versions, use issue_fields['versions'] = [{'name': 'v1.0'}]
. just check with your jira admin for the exact epic link field id.
Epic link field IDs change between JIRA instances, so you’ll need to find yours first. Run jira_instance.fields()
to see all available fields and look for one with ‘epic’ in the name - usually something like customfield_10008 or customfield_10014. Got the field ID? Add it like issue_fields['customfield_XXXXX'] = 'EPIC-KEY'
where EPIC-KEY is your actual epic issue key. For affected versions, just use ‘versions’ and pass a list of dictionaries: issue_fields['versions'] = [{'name': 'Version 1.0'}, {'name': 'Version 2.0'}]
. The version names need to match exactly what’s in your JIRA project settings or the API will error out when creating the issue.