I want to programmatically change the value of Epic Status on a bunch of tickets. However I an not figure out what the right dictionary/JSON object structure is in order to get the API to accept an update to this field. I have done quite a few searches for an answer to this one - and have yet to find something that provide a recommendation.
I have created a code snippet to show what I am doing and I have provided the output from two different runs. Deeply appreciated if someone could point me in the right direction here.
CODE:
import pprint
pp = pprint.PrettyPrinter(indent=4)
from atlassian import Jira
url= 'your-url',
username= 'your-account'
token='your-token-or-password'
ticket='NCCWEB-7919'
def jira_find_field( jira, fld, dumpall=False ):
results = jira.get_all_fields()
if dumpall:
pp.pprint(results)
return
for result in results:
if fld == result['name']:
pp.pprint(result)
jira = Jira(
url=url,
username=username,
password=token)
print('Field information in our instance')
jirafld = 'Epic Status'
jira_find_field( jira, jirafld )
# try different structures
jira_epic_done_field_formats = [
{ "customfield_10010" : [{"value" : "Done",}],},
{ "customfield_10010" : {"value" : "Done",},},
{ "customfield_10010" : "Done" },
]
print('-'*80)
print('Current value for this field')
result = jira.issue_field_value( ticket, "customfield_10010" )
print(result)
for jira_epic_done_fields in jira_epic_done_field_formats:
print('-'*80)
print(jira_epic_done_fields)
try:
result = jira.update_issue_field( ticket, jira_epic_done_fields )
print('epic status updated')
except Exception as e:
print(e)
RESULTS:
Field information in our instance
{ 'clauseNames': ['cf[10010]', 'Epic Status'],
'custom': True,
'id': 'customfield_10010',
'key': 'customfield_10010',
'name': 'Epic Status',
'navigable': True,
'orderable': True,
'schema': { 'custom': 'com.pyxis.greenhopper.jira:gh-epic-status',
'customId': 10010,
'type': 'option'},
'searchable': True,
'untranslatedName': 'Epic Status'}
--------------------------------------------------------------------------------
Current value for this field
{'self': 'https://<your-instance>atlassian.net/rest/api/2/customFieldOption/10003', 'value': 'Done', 'id': '10003'}
--------------------------------------------------------------------------------
{'customfield_10010': [{'value': 'Done'}]}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7899
--------------------------------------------------------------------------------
{'customfield_10010': {'value': 'Done'}}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7899
--------------------------------------------------------------------------------
{'customfield_10010': 'Done'}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7899
================================================================================
Field information in our instance
{ 'clauseNames': ['cf[10010]', 'Epic Status'],
'custom': True,
'id': 'customfield_10010',
'key': 'customfield_10010',
'name': 'Epic Status',
'navigable': True,
'orderable': True,
'schema': { 'custom': 'com.pyxis.greenhopper.jira:gh-epic-status',
'customId': 10010,
'type': 'option'},
'searchable': True,
'untranslatedName': 'Epic Status'}
--------------------------------------------------------------------------------
Current value for this field
{'self': 'https://<your-instance>atlassian.net/rest/api/2/customFieldOption/10001', 'value': 'To Do', 'id': '10001'}
--------------------------------------------------------------------------------
{'customfield_10010': [{'value': 'Done'}]}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7919
--------------------------------------------------------------------------------
{'customfield_10010': {'value': 'Done'}}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7919
--------------------------------------------------------------------------------
{'customfield_10010': 'Done'}
400 Client Error: for url: https://<your-instance>atlassian.net/rest/api/2/issue/NCCWEB-7919