I want to update JIRA issue status. What have I done so far?
Firstly I get the transition ids with;
https://hostname/rest/api/2/issue/{issueKey}/trans itions
This returned me(shorten form);
{ "expand":"transitions", "transitions":[ { "id":"11", "name":"To Do" }, { "id":"21", "name":"In Progress" }, { "id":"31", "name":"In Review" }, { "id":"41", "name":"Done" } ] }
To be able to do the transition;
var url = "https://hostname/rest/api/2/issue/{issueKey}/transitions"; var message = [{ "update": { "comment": [{ "add": { "body": "comment" } }], "worklog" : [{ "add": { "timeSpent" : "timeSpent" } }] }, "fields": { "resolution": { "name": "To Do" } }, "transition": { "id": "11" } }]; request({ url: url, method: "POST", json: true, body: message }, function (error, result){ if(error){ nresponse.error(res, error); }else{ console.log(result); } });
This code snippet doesn't throw an error. Actually it returns successfully. But when I check the status, comment section of the issue, I see that nothing has changed. What am I missing? How can I update the JIRA issue status with `node.js`?
console.log(result);
returns as;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Connect Error</title> </head> <body> <div id="pagecontainer"> <h1>Could not connect to server</h1> <div class="row"> <p class="label">Overview:</p> <p class="item">Could not connect to hostname.</p> </div> <div class="row"> <p class="label">Details:</p> <p class="item">The remote side uses a protocol version that is not enabled</p> </div> <div id="options"> <p class="label">Options:</p> <form action=""><input type="button" class="button" onclick="history.back();" value=" Go Back "></form><p class="item">Pressing the button allows you to go to the previous page.</p> <p class="last-item">You can try to reload the page or check if the URL is correct.</p> </div> <div style="clear: both; overflow: hidden; height:1px;"></div> </div> </div> </body> </html>
What is the meaning of this result? What am I missing?
Hey Zeynep,
I was about to give an answer because I have a working example, but you have edited your post to remove the content.
Do you still need help or did you find the problem?
Hey Sam,
I realize that I didn't include my JIRA username and password. When I add them to POST, it solved problem. And I couldn't delete my post. But now, I realize that I can't add a comment while changing the issue status by api.
How can I resuscitate my post?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've edited your post to put back the details of your original question.
I think the comment will only work if the transition you are doing has a screen where the user could actually add comments if using the JIRA GUI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for editing the question:)
I couldn't understand what you have said, is it not possible to add a comment while changing the status of an issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In document I've seen; https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-doTransition
It includes comment section in update object, I also follow it, but couldn't get a result. Why?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can add a comment, but I think it depends on the details/set-up of the transition you are executing. If that transition allows a comment, you can add one.
I'll check my test set up and get back to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This simplified version of your code works OK for me:
var request = require('request'); var url = "https://hostname/rest/api/2/issue/{issueIdOrKey}/transitions"; var message = { "update": { "comment": [{"add": {"body": "Test comment."}}] }, "transition": {"id": "21"} }; request({ url: url, method: "POST", json: true, body: message, auth: {user: "username", pass: "password"} }, function (error, response, body) { if (!error && response.statusCode === 204) { console.log("OK"); } else if (error) { console.log(error); } else { console.log(response.statusCode); } });
I find that the test comment only works if the JIRA workflow is set up to show a screen during the transition I am excecuting.
In other words the API respects the settings that apply to the JIRA UI. If you can't add a comment during the transition via the UI, then you can't do it via REST either. I found some info in this old question to back that up.
You can check which transitions ids have a screen, and which fields are available, by making a GET request, with the 'expand' parameter, like this:
https://hostname/rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields
Look for those where 'hasScreen' = true.
So in this example, I can add a comment when doing transition id 21, but cannot add a comment when doing transition id 11:
{ expand: "transitions", transitions: [ { id: "11", name: "To Do", to: {...}, hasScreen: false, fields: {... } }, { id: "21", name: "In Progress", to: {...}, hasScreen: true, fields: {...} ...etc...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
p.s. I guess the example in the Atlassian REST documentation (https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-doTransition) includes examples of stuff in the update and fields parameters to show how it can be done if your transition does have a screen where fields/comments can be set.
It does imply that not all fields can be set, since it mentions how those than can be set can be determined:
"The fields that can be set on transtion, in either the fields parameter or the update parameter can be determined using the /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields resource. "
But it could be clearer about the comments.
Where you can't add a comment in a particular transition, I suppose you can always do it a second call to /rest/api/2/issue/{issueIdOrKey}/comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is interesting.
https://hostname/rest/api/2/issue/{issueIdOrKey}/
transitions?expand=transitions.fields
returns me as;
{ "expand":"transitions", "transitions":[ { "id":"11", "name":"To Do", "to":{ "self":"https://hostname/rest/api/2/status/10000", "description":"", "iconUrl":"", "name":"To Do", "id":"10000", "statusCategory":{ "self":"https://hostname/rest/api/2/statuscategory/2", "id":2, "key":"new", "colorName":"blue-gray", "name":"To Do" } }, "fields":{ } }, { "id":"21", "name":"In Progress", "to":{ "self":"https://hostname/rest/api/2/status/3", "description":"This issue is being actively worked on at the moment by the assignee.", "iconUrl":"https://hostname/images/icons/statuses/inprogress.png", "name":"In Progress", "id":"3", "statusCategory":{ "self":"https://hostname/rest/api/2/statuscategory/4", "id":4, "key":"indeterminate", "colorName":"yellow", "name":"In Progress" } }, "fields":{ } }, { "id":"31", "name":"In Review", "to":{ "self":"https://hostname/rest/api/2/status/10100", "description":"", "iconUrl":"https://hostname/", "name":"In Review", "id":"10100", "statusCategory":{ "self":"https://hostname/rest/api/2/statuscategory/4", "id":4, "key":"indeterminate", "colorName":"yellow", "name":"In Progress" } }, "fields":{ } }, { "id":"41", "name":"Done", "to":{ "self":"https://hostname/rest/api/2/status/10001", "description":"", "iconUrl":"https://hostname/", "name":"Done", "id":"10001", "statusCategory":{ "self":"https://hostname/rest/api/2/statuscategory/3", "id":3, "key":"done", "colorName":"green", "name":"Done" } }, "fields":{ } } ] }
There is no field as "hasScreen"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's probably a version difference. What version of JIRA do you have?
I assumed JIRA Cloud as you linked to the Cloud REST API docs, but maybe you have JIRA Server?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's JIRA Server, then. There are some subtle differences between the APIs.
Here are the relevant docs:
For JIRA Server, which doesn't include the 'hasScreen' field:
https://docs.atlassian.com/jira/REST/server/#api/2/issue-getTransitions
For JIRA Cloud, which does include the 'hasScreen' field:
https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getTransitions
Not sure why the difference. Confusing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.