Need help with JIRA Python library for ticket creation

I’m working on a script that creates tickets in JIRA using Python but I’m running into some problems. The basic ticket creation works fine but I can’t figure out how to properly set the affected versions and epic link fields.

Here’s my current code:

from jira import JIRA
import pandas as pd

email = '[email protected]'
token = 'my_api_token'
jira_url = 'https://mycompany.atlassian.net'

config = {'server': jira_url}
jira_client = JIRA(config, basic_auth=(email, token))

ticket_data = []

df = pd.read_excel('tickets.xlsx')
for row in df.index:
    ticket_info = {}
    ticket_info['project'] = {'key': 'PROJ'}
    ticket_info['summary'] = df['Title'][row]
    ticket_info['description'] = df['Details'][row]
    ticket_info['issuetype'] = {'name': 'Task'}
    ticket_info['priority'] = {'name': df['Priority'][row]}
    ticket_info['labels'] = [df['Tags'][row]]
    ticket_info['reporter'] = {'name': df['Reporter'][row]}
    ticket_info['assignee'] = [df['Assignee'][row]]
    
    created_ticket = jira_client.create_issue(fields=ticket_info)
    print(created_ticket)

The main issue is that I can’t add the versions field or link it to an epic. Has anyone dealt with this before?

Had the same problem with JIRA custom fields. Epic links are tricky because the field ID changes between instances. Here’s a quick fix: create a ticket manually with the epic link, then run jira_client.issue(‘TICKET-123’) to see all the field data. Look for the epic reference there. For versions - make sure they actually exist in your project first, or the API call will bomb. Also, you’re using ‘versions’ for affected versions, but if you want fix versions, use ‘fixVersions’ with the same structure. One last tip: wrap your create_issue call in try-except. These custom fields throw really cryptic errors that’ll drive you nuts without proper error handling.

I ran into the same problems when I started automating JIRA tickets. For affected versions, format it like this: ‘versions’: [{‘name’: ‘your_version_name’}]. The version name has to match exactly what’s in your JIRA project settings. For epic linking, you need the custom field ID first - usually something like customfield_10008 or customfield_10014. Check an existing ticket’s JSON response or ask your JIRA admin. Then add ‘customfield_XXXXX’: ‘EPIC-123’ where XXXXX is your field ID. Also, your assignee field uses a list but should be a dictionary: {‘name’: df[‘Assignee’][row]}.

for epic links, use customfield_10014 (check your jira admin settings for the exact field ID). for versions, add ‘fixVersions’: [{‘name’: ‘version_name’}] to your ticket_info dict. also, your assignee field should be a dict, not a list.