Updating Multi-Select Field

Travis Simpson September 24, 2018

Hi all, 

I've found some matches to my question and tried working through them but was unsuccessful so I'm reaching out for additional help.

 

What I'm trying to do:

  • Jira tickets get created when issues happen in our system and the description of the ticket can contain one or more values for the root cause of the ticket being created. I want to have a multi-select field with all of these potential values available and when this script runs it will do a REGEX match to get all of the values in the ticket and then updated the Jira ticket to put them in the actual Root Cause field (multi-select)

 

Where I'm stuck:

 

I'm able to:

  • GET all available values for the custom field
  • Match and parse out the matched value into a variable

I'm not able to:

  • Update the field with a POST request.

 

What I've tried:

  • I have tried solving this by only working with the REST POST request but I'm getting 405 status errors and no response body, I'm clearly missing something.

 

When I use cURL:

  • Command: curl -i -u username:password -X POST -H "Content-Type:application/json Accept:application/json X-Atlassian-Token:nocheck" https://domain/rest/api/2/issue/ITS-9100/editmeta -d '{'update' : {'customfield_13222' : [{'add' : {'value' : 'The_value_in_the_custom_field'}}]}}'
  • Result: Access Denied

 

When I use Insomnia (Postman equivalent):

  • Status 405 (no body returned for response)

 

 

I'd post the full source but it probably won't be useful because everything appears to work except for the update of the ticket at the end.

 

2 answers

1 accepted

0 votes
Answer accepted
Travis Simpson September 25, 2018

So it turns out POST is not available for the http://domain/rest/api/2/issue/{issueIdOrKey} endpoint so a PUT request is required. The correct json to send as well as the whole request (using the Python requests library) is below.

update_url = 'https://' + credentials.JIRAPOCDomain + '.atlassian.net/rest/api/2/issue/' + str(key)
update_headers = {'Content-Type': 'application/json', 'Accept': 'application/json','X-Atlassian-Token': 'no-check'}
update_data = {"update" : {"customfield_13222" : [{"add" : {"value" : root_cause_value}}]}}
request = requests.put(update_url,data=json.dumps(update_data),headers=update_headers,auth=(username,token)) 

 

key is the jira issue key

root_cause_value is a variable that stores the value I'm trying to add to the custom field

2 votes
Fazila Ashraf
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 25, 2018

Hi @Travis Simpson

Are you sure you want to use http://domain/rest/api/2/issue/{issueIdOrKey}/editmeta and not http://domain/rest/api/2/issue/{issueIdOrKey}

Travis Simpson September 25, 2018

I actually figured it out after I posted this but my post wasn't showing up in my history or anything so I couldn't update it with the answer, now that it actually shows up I'm going to update everything, thanks for your response. What I didn't realize is the API I was calling doesn't allow POST, so I used PUT instead. I also had to use http://domain/rest/api/2/issue/{issueIdOrKey} and NOT http://domain/rest/api/2/issue/{issueIdOrKey}/editmeta

 

This is the correct form of it

update_url = 'https://' + credentials.JIRAPOCDomain + '.atlassian.net/rest/api/2/issue/' + str(key)
update_headers = {'Content-Type': 'application/json', 'Accept': 'application/json','X-Atlassian-Token': 'no-check'}
update_data = {"update" : {"customfield_13222" : [{"add" : {"value" : root_cause_value}}]}}
request = requests.put(update_url,data=json.dumps(update_data),headers=update_headers,auth=(username,token))

Suggest an answer

Log in or Sign up to answer