How can I close an issue via a rest api call?

Colin Callahan September 11, 2012

I would like to be able to close a Jira Issue via rest api call. Has anyone had any experience doing this? Any help would be greatly appreciated.

thanks,

Colin

4 answers

1 accepted

2 votes
Answer accepted
Colin Callahan September 12, 2012

It turns out I was missing the word " transitions" from the url: rest/api/2/issue/IT-44/transitions. I spent most of the time trying to figure out what was wrong with the body of the request. The documentation for the body is incorrect so always use what you get back from the transitions method call as your documentation: /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields

1 vote
Mavis Chen November 2, 2016

You have to add another workflow from "Any status" to "Closed", 

then find out its id by using this api with GET :

/rest/api/2/issue/{issueIdOrKey}/transitions

Finally, call the same api with POST to forcefully close your case from any status.

Post body should look like:
 {"transition": {"id": "your closed status id"}}

1 vote
Elias Karakoulakis February 4, 2014

I'm afraid there's still an ongoing issue with REST and resolving issues (so that would make this a metaissue :) )

- We need a transition identifier in order to perform a transition, not just its textual representation.

- The only way I'm aware of right now to get that transition ID is via the following REST GET call: api/2/issue/<issue_key>/transitions?expand=transitions.fields

- This is NOT working for issues with workflows having global/common transition defined. (I'm getting the same NPE as the one described in https://jira.atlassian.com/browse/JRA-32132)

- There is a suggested fix dated 26/Jul/2013 which other users suggest its working for them

This is crucial in that it prevents our transition from using SOAP (which AFAIK is scheduled to be removed in Jira 7) to REST.

Warm regards,

Elias

0 votes
Jobin Kuruvilla [Adaptavist]
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.
September 11, 2012
Colin Callahan September 12, 2012

Jobin, I can't seem to get this to work. This json updates the summary but does nothing for the status.

{

"fields":

{

"summary": "Updated summary"

},

"transition":

{

"status": "Closed"

}

}

Any thoughts?

Norman Abramovitz
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.
September 12, 2012

Your transition section looks wrong to me. It should look more like

"transitions": { "id": "2" }

The number needs to correspond to your closed transition.

http://docs.atlassian.com/jira/REST/latest/#id128971
Colin Callahan September 12, 2012

Thanks for the input Jobin and Norman. I've tried both of your examples and it is not working. It could be a bug.

Has anyone had any success closing issue from the rest api?

Norman Abramovitz
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.
September 12, 2012

What transitions are allowed from the state you are in? What does the your rest call for getting transitions show you? What does your request for changing transitions look like? What does the reponse message for changing transitions look like? What does your jira logs show you about your request and its response? Probably need to ask support about help looking at the logs since you are using OnDemand.

What does your http request lines look like? I would put my money on incorrect http packet or the user you are doing the request with does not have permission to close issues.

Colin Callahan September 12, 2012

@Norman: Thanks for the great questions.

What transitions are allowed from the state you are in? - I'm not sure how to tell.

What does the your rest call for getting transitions show you?-"Resolve Issue" and "Close Issue"

What does your request for changing transitions look like?

If I send this in the body:{\"fields\":{\"summary\":\"Updated Summary 2\"},\"transition\":{\"id\":2}}, the summary field gets updated without error but the transition does not work.

If I send this in the boday: {\"fields\":{\"summary\":\"Updated Summary 2\",\"resolution\":{\"id\":\"1\"}},\"transition\":{\"id\":2}}, I get this error message: {\"errorMessages\":[],\"errors\":{\"resolution\":\"Field 'resolution' cannot be set. It is not on the appropriate screen, or unknown.\"}}, although "resolution" is marked as a required field for "Close Issue" in the transitions and the value I am setting is in the list of allowed values.

I even tried sending it the way the online docs say to send it: "{\"fields\":{\"summary\":\"Updated Summary 2\",\"resolution\":\"1\"},\"transition\":{\"id\":2}}", but that gets me the same error message.

What does the reponse message for changing transitions look like? See the error above.

What does your jira logs show you about your request and its response? Probably need to ask support about help looking at the logs since you are using OnDemand. - I'll check with support about the logs.

What does your http request lines look like? I would put my money on incorrect http packet or the user you are doing the request with does not have permission to close issues - It doesn't seem to be either of these.

Suggest an answer

Log in or Sign up to answer