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

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

Accepted Answer
2 votes

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

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

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?

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

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?

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.

@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.

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"}}

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

78 views 0 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you