I have created a single selection custom drop down field and want to import a long list of available selections into JIRA for this field without having to do them one at a time (e.g., country names)?
Hello Steve, I'm Adriana Hernández from the ServiceRocket team.
By utilizing the Jira Cloud API alongside Python3, it is possible to add new values to a select list custom field in Jira through the use of a CSV file.
Please see the Python3 script below as an example:
import requests
from requests.auth import HTTPBasicAuth
import json
import csv
#variables for the url
jiraInstance = "YOUR_INSTANCE_NAME" #name (the name that goes before .atlassian.net)
fieldId = "customfield_0000"
contextId = "0000" #ConfigSchemeId=
auth = HTTPBasicAuth("YOUR_EMAIL", "YOUR_TOKEN")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
#List
options_create = []
options = []
#CSV route
file = '/Users/YOUR_USER/Desktop/YOUR_FILE.csv' #here goes the path to the CSV that contains the options, e.g., my file is in the desktop.
def getoptions():
with open(file) as file_obj:
heading = next(file_obj) #skip headers in csv.
reader_obj = csv.reader(file_obj) #with this function we can read and manage the csv.
for row in reader_obj:
options_create.append(row[0]) #creating a list with the option entries of the row 0.
options_unique = list(set(options_create)) #Local variable to get unique option values.
for option in options_unique: #go trough each 'option' value on the option_unique list.
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
url = f"https://{jiraInstance}.atlassian.net/rest/api/3/field/{fieldId}/context/{contextId}/option"
payload = json.dumps({
"options": [{
"value": option
}]})
response = requests.request(
"POST",
url,
data=payload,
headers=headers,
auth=auth
)
print(response.status_code)
getoptions()
Hi Steve,
You might consider using a third-party plugin for the import task. If you only need to import values once, remember that you don’t have to keep the plugin installed afterward. One such plugin is "External Data for Jira Fields," which allows you to use a CSV file as a data source. With the "Field Option Sync" configuration, you can sync values from the CSV into a native Jira select-list field either once or continuously if the file changes often.
After uninstalling the app, the field options synced will remain intact, making it technically a one-time import. I should disclose that I am involved with the vendor of this app, but it remains a technically free option.
I hope this helps.
Thomas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.