Error while trying to update a custom field using REST API

Mahesh January 5, 2018

I am trying to implement a functionality to auto close few tickets which meets a criteria. I am getting the errors mentioned below while making the API call to resolve the issue.

Command I am running:

curl -D- -u admin:admin -X POST --data @oracle_decomm_close_2 -H "Content-Type: application/json" "https://jiraxx.xxxx.com/rest/api/2/issue/DECOM-40322/transitions?expand=transitions.fields" 

cat oracle_decomm_close_2
{
"update": {
"comment":[{"add": {"body": "Automatic closure of Oracle decommission ticket"}}],
"worklog":[{"add": {"timeSpent":"1m"}}],
"customfield_14881":{"value": "NO"}
},"transition": {"id": "5"}
}

Error:

{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: com.plugenta.jiraauditor.filter.RestReadingServletRequest$1@388e8ec2; line: 1, column: 139] (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]}

 

New to json. Any help on this is highly appreciated.

 

1 answer

0 votes
Alexey Matveev
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.
January 5, 2018

Hello,

Do you mean that the problem is with customfield_14881? Are you sure about it? Did you try to do the POST without customfield_14881? Did it work? If you are sure that the problem is withcustomfield_14881then what is customfield_14881 custom field type?

Mahesh January 8, 2018

Thanks for getting back Alexey.

 

I am not quite sure where the problem is. I figured that customfield_14881 is required to transition the ticket status to "Resolved". It wouldnt let me close the ticket from the front end, if this field is not set.

 

I am not sure how to find the type of the custom field. But I did a GET on an existing ticket, and found the below for this particular custom field.

"customfield_14881": {
"id": "17533",
"self": "https://jiraxx.xxxx.com/rest/api/2/customFieldOption/17533",
"value": "NO"
}

 

Please excuse my mistakes. Any help or guidance is appreciated.

Alexey Matveev
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.
January 8, 2018

Your JSON should be like this

{
"update": {
"comment":[{"add": {"body": "Automatic closure of Oracle decommission ticket"}}],
"worklog":[{"add": {"timeSpent":"1m"}}]
},

"fields": {
    "customfield_14881":{"value": "NO"}
  },"transition": {"id": "5"}
}

Mahesh January 8, 2018

Tried that.

 

I get HTTP/1.1 500 Internal Server Error

 

Can I enable additional logging to see specific errors?

Alexey Matveev
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.
January 8, 2018

Have a look in your atlassian-jira.log. It should work. The problem was that

"customfield_14881":{"value": "NO"} was in the update parameter. But it must be in the fields parameter. Aslo I supposed that your custom field is a single select

Mahesh January 8, 2018

Thanks Alexey.

 

Unfortunately I dont have access to the application logs. I will keep looking to get them.

 

Adding the custom field change to fields parameter still hasn't worked.

Alexey Matveev
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.
January 8, 2018

What is the error?

Mahesh January 8, 2018

I just get this when i execute the curl command.

 

{"errorMessages":["Internal server error"],"errors":{}}

Mahesh January 8, 2018

The custom field is indeed single select. From the front end i see the possible options are YES/NO

Mahesh January 8, 2018

Capture.JPG

Alexey Matveev
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.
January 8, 2018

Try to install Jira REST API browser add-on(it is free) and check it there. You can query all REST API functions there. Have a look what will be the error there.

Mahesh January 10, 2018

Thanks Alexey. Turns out the id I gave in the transition was incorrect.

 

It worked after I gave the right one.

 

Thanks for your help.

Dheeraj Shetty November 3, 2022

I am getting this 500 status code when I am using below payload in my post request
{
"transition": {
"id": "41"
}
}

Suggest an answer

Log in or Sign up to answer