How to change status of an issue using REST API 'issue' ?

Mohamed Abdul Kader March 3, 2015

Hi Guys,

Im trying to change the status of an issue using the REST API (through CURL). But it doesn't work out.

API details : https://docs.atlassian.com/jira/REST/latest/#d2e364

CURL response is

{"errorMessages":["Internal server error"],"errors":{}}

Doing a CURL POST to https://jira.xxx.com/rest/api/latest/issue/37143/transitions

37143 is the id of the issue. I also tried with 'key' of the issue.

The payload for the CURL is as below,

{"transition":{"id":"10139"}}

10139 is the id of the new status expected. The user has access permission and this transition is possible from the current status of the issue. Not only this status failed, all other possible statuses are also failed with the same error message.

Below is my code which performs the operation.

$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_POST => 1,
	CURLOPT_URL => JIRA_URL . '/rest/api/latest/' . 'issue/37143/transitions',
	CURLOPT_USERPWD => USERNAME . ':' . PASSWORD,
	CURLOPT_POSTFIELDS => {"transition":{"id":"10139"}},
	CURLOPT_HTTPHEADER => array('Content-type: application/json'),
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_FOLLOWLOCATION => 1,
	CURLOPT_SSL_VERIFYPEER => 0,
	CURLOPT_SSL_VERIFYHOST => 0
));
$result = curl_exec($ch);

Am i doing anything wrong ? Any help is very much appreciated.

Thanks in Advance
-- Abdul Kader

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2015

Hello Abdul,

Thank you for your question.

You are able to get the transitions ID by hitting the following in your web browser:

# issueIdOrKey, used "ABC-1"
http://[jira-base-url]/rest/api/latest/issue/[issueIdOrKey]?expand=transitions

Running the above, in my case it returned the following:

... "transitions":[{"id":"71","name":"Start Review","to":{"self":"http://[jira-base-url]/rest/api/2/status/10001","description":"","iconUrl":"http://[jira-base-url]/images/icons/statuses/information.png","name":"In Review","id":"10001","statusCategory":{"self":"http://[jira-base-url]/rest/api/2/statuscategory/1","id":1,"key":"undefined","colorName":"medium-gray","name":"No Category"}}},{"id":"151","name":"Done","to":{"self":"http://[jira-base-url]/rest/api/2/status/10000","description":"","iconUrl":"http://[jira-base-url]/images/icons/statuses/closed.png","name":"Done","id":"10000","statusCategory":{"self":"http://[jira-base-url]/rest/api/2/statuscategory/1","id":1,"key":"undefined","colorName":"medium-gray","name":"No Category"}}},{"id":"161","name":"To Do","to":{"self":"http://[jira-base-url]/rest/api/2/status/10002","description":"","iconUrl":"http://[jira-base-url]/images/icons/statuses/open.png","name":"To Do","id":"10002","statusCategory":{"self":"http://[jira-base-url]/rest/api/2/statuscategory/1","id":1,"key":"undefined","colorName":"medium-gray","name":"No Category"}}}]}

Then, I have set up the cURL as per following

<?php
$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_POST => 1,
	CURLOPT_URL => 'http://[jira-base-url]/rest/api/latest/' . 'issue/ABC-1/transitions',
	CURLOPT_USERPWD => "admin:admin",
	CURLOPT_POSTFIELDS => '{"transition":{"id":"161"}}',
	CURLOPT_HTTPHEADER => array('Content-type: application/json'),
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_FOLLOWLOCATION => 1,
	CURLOPT_SSL_VERIFYPEER => 0,
	CURLOPT_SSL_VERIFYHOST => 0
));
$result = curl_exec($ch);
curl_close ($ch);
?>

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

Mohamed Abdul Kader March 4, 2015

Thanks Rafael.. It works.. All the while it was passing the id of the "Status" (https://xxx.com/secure/admin/ViewStatuses.jspa) and not id of the "Transition"..

0 votes
Rahul K March 3, 2015

Which JIRA version are you using? There are some bugs reported to Atlassian for Status checks via REST:

https://jira.atlassian.com/browse/JRA-31186

https://jira.atlassian.com/browse/JRA-33359

https://jira.atlassian.com/browse/JRA-32132

Your issue looks similar to these ones.

Try to do a simple GET request with similar data and see if that works.

-Rahul

Mohamed Abdul Kader March 3, 2015

Thanks for the quick response.. A simple GET with similar data also returns the same error message.. My version of JIRA is "Atlassian JIRA Project Management Software (v6.2.6#6264-sha1:ee76422)"

TAGS
AUG Leaders

Atlassian Community Events