Unable to update custom field in jira using REST API

Sach March 8, 2021

I have a jira custom field that I got created by the admins. It is a dropdown with 2 possible field values. One of them is set as a default. 

In my shell script from where the data is created, I am trying to update the same custom field to the value which is not the default (if certain conditions are met). After the condition is met, and I am getting the correct value for $customfield1(the other non-default value) and $key(issue number)

I am firing this

curl --silent -D- -u charlie:charlie -X PUT --data {"fields" : {"customfield1": $customfield1}} -H "Content-Type: application/json" -w "\n%{http_code}"https://jira.company.com/rest/api/2/issue/$key

However, no matter what I try, my issue is getting created with the default value of the customfield1.  I am not able to override with my other value via this command. Any thoughts?

 

1 answer

0 votes
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2021

Hi @Sach 

Two things to try :

  1. Have you tried within Jira using the UI that you're able to change that customfield away from it's default to the other value?
  2. If 1. above works, then try using the API to only update an existing issue and change the customfield's value from the default to the other value. If that also works, you may need to consider doing it in 2 steps - create the issue with one API call then use another API call to change the customfield
Sach March 8, 2021

Hi @Warren 

Thank you for responding.  1 works if I just open the ticket and update it manually.

Let me try the second point you listed above.

Sach March 10, 2021

Via the linux command line, I tried the below 4 methods to update the existing Jira issue each of which gave me the following errors :

Command 1:
curl -D- -u charlie:charlie -X PUT --data {"update" : {"customfield_38101": [{"set" : "ABC"}]}} -H "Content-Type: application/json" -w https://jira.company.com/rest/api/2/issue/COMP-1022

curl: (6) Couldn't resolve host ':'
curl: (3) [globbing] unmatched brace at pos 20
curl: (3) [globbing] illegal character in range specification at pos 2
curl: (6) Couldn't resolve host ':'


-----------------

Command 2:
curl -D- -u charlie:charlie -X PUT --data {"fields": {"customfield_38101": {"value":"ABC"}}} -H "Content-Type: application/json" -w https://jira.company.com/rest/api/2/issue/COMP-1022


curl: (3) [globbing] unmatched brace at pos 20
curl: (6) Couldn't resolve host 'value:ABC'


--------------------------------

Command 3:
curl -D- -u charlie:charlie -X PUT --data "{\"fields\" : {\"customfield_38101\": [{ \"value\": \"ABC\" }]}}" -H "Content-Type: application/json" https://jira.company.com/rest/api/2/issue/COMP-1022

{"errorMessages":[],"errors":{"customfield_38101":"Could not find valid 'id' or 'value' in the Parent Option object."}}


--------------------

Command 4:
curl -D- -u charlie:charlie -X PUT --data "{\"fields\" : {\"customfield_38101\": [{ \"value\": \"id\": \"52803\" }]}}" -H "Content-Type: application/json" https://jira.company.com/rest/api/2/issue/COMP-1022

{"errorMessages":["Unexpected character (':' (code 58)): was expecting comma to separate OBJECT entries


Any suggestions to either of the above ? I tried several options from the Atlassian's documentation like using update, fields, set, etc .  From the editmeta I was able to identify the custom field number and the value ID I needed but just not able to edit it

Suggest an answer

Log in or Sign up to answer