Cannot transition an issue via Rest API

Robbie LaBarbera October 3, 2019

I've been trying to transition an issue via Rest API for over a week now with no success. I've been able to create an issue, add a comment, change the assignee.. but not transition to a different status.

Here's my work:

I first determine the transition IDs - It's currently In Progress, and I'm wanting to Close it.

The following is shown after "rest/api/2/issue/REL-10569/transitions?expand=transitions.fields" is appended to the jira server:

{"expand":"transitions","transitions":[{"id":"21","name":"Close","to":{"self":"https://jira.bullhorn.com/rest/api/2/status/6","description":"The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.","iconUrl":"https://jira.company.com/images/icons/statuses/closed.png","name":"Closed","id":"6","statusCategory":{"self":"https://jira.company.com/rest/api/2/statuscategory/3","id":3,"key":"done","colorName":"green","name":"Done"}},"fields":{}}]}

 

So I'm wanting to use transition ID 21 (I'm assuming - I've tried the other IDs any they did not do anything either).

I'm using a user with full admin permissions - the following is my script:

api_data="{\"update\":{\"comment\":[{\"add\":{\"body\":\"It is time to finish this task\"}}]},\"fields\":{\"assignee\":{\"name\":\"username\"},\"resolution\":{\"name\":\"Done\"}},\"transition\":{\"id\":\"21\"}}"

curl -D- -u "username":"${password}" -w "<%{http_code}>" -H "Content-Type: application/json" https://jira.company.com/rest/api/2/issue/${TICKETNUMBER} -X PUT --data "${api_data}"

 

This script successfully adds a comment and assigns the issue, returning a 204 No Content code, but no transition is made into the next workflow status.

 

I've also read that transition can only be set with a Post, so I also tried the following:

api_data="{\"transition\":{\"id\":\"21\"}}"

curl -D- -u "username":"${password}" -w "<%{http_code}>" -H "Content-Type: application/json" https://jira.company.com/rest/api/2/issue/${OUTBOUNDRELTICKET}/ -X POST --data "${api_data}"

This returns 405 method not allowed.

I've also read that /transitions needs to be appended to server name in the curl, after the ticket number - this returns a 500 Internal Server Error.

 

 

So I believe I have tried Everything that is on the internet, but nothing works. I'm desperate... please help!

 

1 answer

1 accepted

2 votes
Answer accepted
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 3, 2019

Hi Robbie and Welcome,

Do you mind to try the following?

curl -u username:password -X POST --data '{"transition":{"id":"21"}}' -H "Content-Type: application/json" http://jira.company.com/rest/api/2/issue/{issueKey}/transitions

 

Does it work?

Regards.

Robbie LaBarbera October 3, 2019

It... certainly.. did. 

Wow. Thank you.

Can you tell me what I was doing wrong - or why this worked?

RianS
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.
October 3, 2019

From looking at what you have above and the response. It looks like you were trying the "Edit Issue" rest call instead of the "Do transition" REST call. The difference is the added /transitions after the issue number.

The "Do Transition" REST call does allow for the updating of fields as part of the call so you can do it all in one, but the "Edit Issue" doesn't perform transitions as part of the update.

The "Do Transition" is a POST instead of "Edit Issues" PUT as well.

For those that read this, the Server REST API documentation for transitions is located at:

https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/issue-doTransition

Like # people like this
Jack Nolddor _Sweet Bananas_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 3, 2019

Hi Robbie as @RianS already explained to transition an issue you must use the transition endpoint instead.

 

Did my answer solve your problem?

If so, consider to mark the proposed solution as an 'Accepted answer'. This will help other people with the same or a quite similar problem to find a solution in a easy and faster way.

In addition, by doing this the post will automatically gain the "Solved:" prefix in search results to indicate other people that no further support is needed.

Kind Regards.

Like Robbie LaBarbera likes this
Robbie LaBarbera October 3, 2019

You all are incredible - thank you so much, appreciate your time. I not only have a fix now, but understand the reasoning behind it. 

Suggest an answer

Log in or Sign up to answer