Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update the status on a Jira issue vis Jira Rest Api

I want to change the status of the project issue on Jira. The status is Open and I want to make it Fixed. My url is PUT https://jiradbg-sandbox.deutsche-boerse.de/rest/api/latest/issue/PID-XX

{
    "update": {
        "fields":{
            "status": [
                {
                    "set": "Fixed"
                }
            ]
        }
    }
} 

and the response is:

{
    "errorMessages": ["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@5de98556; line: 3, column: 9] 
(through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]
}
like image 955
Renos Bardhis Avatar asked Oct 17 '25 21:10

Renos Bardhis


1 Answers

There are two problems that you are encountering here.

The first problem is update or fields should be provided separately to Jira's edit issue API, not one inside of the other. They have equivalent functionality so normally only one is used. For example to update the summary field provide either update:

{
  "update": {
    "summary": [
      {
        "set": "Updated by update"
      }
    ]
  }
}

or fields:

{
  "fields": {
    "summary": "Summary set by fields"
  }
}

However the status field is a special case and can't be updated directly, which is the second problem here. Changing a status in Jira is called a transition. You need to trigger the transition to move the issue into the status you want.

Start by identifying the available transitions by calling the get transitions API:

GET https://example.net/rest/api/latest/issue/PID-XX/transitions

This tells you which transitions are currently available, something like this:

{
  "expand": "transitions",
  "transitions": [
    {
      "id": "21",
      "name": "Fixed",
      "to": {
        "self": "https://example.net/rest/api/2/status/10001",
        "description": "",
        "iconUrl": "https://example.net/images/icons/status_generic.gif",
        "name": "Fixed",
        "id": "10001",
        "statusCategory": {
          "self": "https://example.net/rest/api/2/statuscategory/3",
          "id": 3,
          "key": "done",
          "colorName": "green",
          "name": "Done"
        }
      }
    }
  ]
}

Take the id of the transition you want, in this case 21, then post it to the issue transition API:

POST https://example.net/rest/api/latest/issue/PID-XX/transitions

Use a request body like this:

{
  "transition": {
    "id": 21
  }
}

You should get a 204 HTTP response from Jira which indicates the transition was successful.

like image 166
gutch Avatar answered Oct 22 '25 08:10

gutch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!