5

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

Anuj Balan
  • 7,205
  • 23
  • 52
  • 89

2 Answers2

8

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

Anuj Balan
  • 7,205
  • 23
  • 52
  • 89
  • When I execute the first command, I get an empty transitions array. Then after executing the second command with transition id of 5, I get an internal server error. – kaushalpranav Nov 27 '17 at 04:20
  • can we not set the status while creating issue? Mean in the same request while creating issue. – Farooq Khan Feb 26 '18 at 06:42
0

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()
                 )
RanonKahn
  • 743
  • 7
  • 21