Unable to resolve issues via Restful API

Thom Wong September 25, 2015

Hello all!

 

I'm having a bit of trouble resolving issues via the API, I'm using Node.js to hit the endpoint and I maybe confused about which id I should be using.   

function closeTicket(ticket) {
var closingId = "10000";
  if (typeof(ticket.key) === 'undefined') {
    return reject(ticket);
  }
  ticket.key + "/transitions/?expand=transitions.fields&transitionId=5";
  var url = "https://" + JIRA_USER + ":" + JIRA_PASS + "@dbisoftware.atlassian.net:443/rest/api/2/issue/" + ticket.key + "/transitions";
  return new Promise((resolve, reject) => {
    request({
      url : url,
      body: JSON.stringify({
        "update": {
          "comment": [
            {
              "add": {
                "body": "Bug has been fixed."
              }
           }
        ]
      },
      "fields": {
        "resolution": {
          "name": "Done"
        }
     },
     "transition": {
        "id": closingId
      }
    })

   }, (err, res, body) => {

      if (err) return reject(err);
      ticket._toJira = body;

      console.log(body);
      console.log(ticket);
      return resolve(ticket);
    })
  });
}

 

The following is the response I get back from endpoint

{
"expand": "transitions",
"transitions": [
{
"id": "11",
"name": "Start Progress",
"to": {
"self": "https://dbisoftware.atlassian.net/rest/api/2/status/10407",
"description": "Assignee is currently actively working on issue.",
"iconUrl": "https://dbisoftware.atlassian.net/images/icons/statuses/generic.png",
"name": "In Progress",
"id": "10407",
"statusCategory": {
"self": "https://dbisoftware.atlassian.net/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
}
},
{
"id": "21",   // Should I be using this ID?
"name": "Done",
"to": {
"self": "https://dbisoftware.atlassian.net/rest/api/2/status/10000",
"description": "",
"iconUrl": "https://dbisoftware.atlassian.net/images/icons/statuses/closed.png",
"name": "Done",
"id": "10000",  // Or should I be using this ID?
"statusCategory": {
"self": "https://dbisoftware.atlassian.net/rest/api/2/statuscategory/3",
"id": 3,   // OR maybe this ID?
"key": "done",
"colorName": "green",
"name": "Done"
}
}
}
]
}

 

I've tried all 3 ids listed in the response above but when I visit the ticket the status of the ticket remains unchanged.   

 

Any help would be greatly appreciated!

 

1 answer

1 accepted

0 votes
Answer accepted
Thom Wong September 25, 2015

I've solved by using the following

 

  1. the issue the ID to be used is the top level id (in my case 21)
  2. The end  point should be /rest/api/2/issue/" + ticket.key + "/transitions/?expand=transitions.fields
  3. Method should be 'POST' (d'oh)

 

Suggest an answer

Log in or Sign up to answer