Reputation: 1867
i want to update the issue status as done or true from the rest api, i tried some links and documentations but it failed and not worked, my json data and url is following, please have a look and let me know where i am wrong.
i followed this link to update the issue status as done.
jQuery.ajax({
url :'https://myurl.com/rest/api/latest/issue/10635',
type: 'PUT',
beforeSend : function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + 'QXNjiYIklOZvcxlxhZ3NodXNldA==');
},
data: JSON.stringify({"status":{"id":"10635","name":"done"}}}),
dataType: 'json',
contentType:'application/json; charset=utf8',
success: function(data){
console.log(data);
}
})
My json is following
{"status":{"id":"10635","name":"done"}}}
i checked the response on fiddler but i got the following error in fiddler response.
{"errorMessages":["one of 'fields' or 'update' required"],"errors":{}}
after that i changed my json data as following and that also not worked,
{"update":{"status":{"id":"10635","name":"done"}}}
and then i seen the error in fiddle as following.
{"errorMessages":["Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: org.apache.catalina.connector.CoyoteInputStream@19d2e36; line: 1, column: 12] (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"]}
it killed my 2.5 hours approx, kindly help where i am wrong ?
Upvotes: 3
Views: 8574
Reputation: 1867
I was using the wrong approach, for setting the status as done of the Jira issue you have to send two requests to the server (1) Get request which will return the transaction id for the issue. (2) Post request to the server with the help of transaction id you can make the issue as done, i try to demonstrate following.
(1) Send Get Request to the JIRA server with following url (same url will use for POST request).
https://mycompany.com/rest/api/2/issue/{issueidORkey}/transitions?expand=expand.fields
it will return the following type of details into json mode.
{
"expand": "transitions",
"transitions": [
{
"id": "25",
"name": "Start Progress",
"to": {
"self": "https://mycompany.com/rest/api/2/status/3",
"description": "This issue is being actively worked on at the moment by the assignee.",
"iconUrl": "https://mycomapny.com/images/icons/statuses/inprogress.png",
"name": "In Progress",
"id": "3",
"statusCategory": {
"self": "https://mycompany.com/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
}
}
}
as above you can see there is the transition --> id=25, this id will be use for the POST request, for me i created the JSON as following and now (2) send the POST request through same url as i used above.
{
"update": {
"comment": [{
"add": {
"body": "Comment body"
}
}]
},
"fields": {},
"transition": {
"id": "25"
}
}
for me fields property was not required so i am able to update the issue status as done. :)
Upvotes: 5