Update JIRA ticket status using REST API

24.9k views Asked by At

I am able to create a ticket in JIRA using CURL command and having a json data handy.

curl -D- -u : -X POST --data @< filename> -H "Content-Type: application/json" http://< hostname>:< port>/rest/api/2/issue/

I was now trying to update the status of the ticket generated but was getting the following error. {"errorMessages":[],"errors":{"status":"Field 'status' cannot be set. It is not on the appropriate screen, or unknown."}}

Curl command:

curl -D- -u < user>:< pwd> -X PUT --data @data_update.txt -H "Content-Type: application/json" http://< hostname>:8100/rest/api/2/issue/MTF-3

3

There are 3 answers

2
Anuj Balan On BEST ANSWER

Status is not a field in Jira and thus changing the same on fly is not possible. JIRA API doesn’t have provision for that.

We have to follow the transitions and change accordingly.

First, execute ‘http://localhost:8100/rest/api/latest/issue/MTF -2/transitions?expand=transitions.fields and know the id’s for transitions.

For Eg: transition id for “Stop Progress” is 31, for “Done” is 41.

Once that is known, use the following link by adding values pertaining to your environment:

curl -D- -u <USER>:<PASS> -X POST --data '{"transition":{"id":"<TRANSITION_ID>"}}' -H "Content-Type: application/json" <JIRA_URL>:<JIRA_PORT>/rest/api/latest/issue/<JIRA_ISSUE>/transitions?expand=transitions.fields

Reference: Check Paul grants answer - https://answers.atlassian.com/questions/107630/jira-how-to-change-issue-status-via-rest

0
RanonKahn On

This is working for me since long using R. similar approach should be possible with curl which is used by the 'httr' library.

library(httr)
library(RJSONIO)

x <- list(fields = list(project = c(key = "xxxxxxx"), 
                        status = "Assign",
                        issuetype = c(name = "xxxx"),
                        summary = "xxxxxxx",
                        description = "xxxxxxx",
                        customfield_xxxxxx = c(value = "xxxxxx"),
                        assignee = c(name = "userid"),
                        customfield_xxxxxx = "xxxxxxxx"
            ))

# can add more fields as shown above

response <- POST("https://xxxxxxx.atlassian.net/rest/api/2/issue/",body = toJSON(x), 
                  authenticate(username,passcode, "basic"), 
                  add_headers("Content-Type" = "application/json"), 
                  verbose()
                 )
0
smoore4 On

If you are looking to programtically mark an Issue as Done, you need to either 1) traverse through all of the workflow steps or 2) set this setting for Done:

enter image description here

The rest api call is then something like this:

curl --location 'https://yourdomain.atlassian.net/rest/api/3/issue/ISSUE-KEY/transitions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic blah blah
--data '{ "transition": {
    "id": "91"
    }