API for get transition and history for issues by REST API?

Justin Ellis August 29, 2013

A similar question was asked a couple of years ago and there was apparently no way to do it, but is it possible now? If I make a REST API request like this:

{"jql":"reporter = 'Justin Ellis'","fields":["id","key","Average Time in Status"],"expand":["changelog","transitions","history"]}

I get a response with transition information, but with no time in transition or timestamps for transitions, like:

{   "field": "status",
                                "fieldtype": "jira",
                                "from": "3",
                                "fromString": "In Progress",
                                "to": "5",
                                "toString": "Resolved"
                            },
                            {
                                "field": "resolution",
                                "fieldtype": "jira",
                                "from": null,
                                "fromString": null,
                                "to": "1",
                                "toString": "Fixed"
                            }

I'm trying to grab, say all the time a ticket or tickets from a specific month last year spent in "Open" or "In Progress" status.

2 answers

7 votes
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 29, 2013

I suppose that you need expand=changelog. This will show you issue changes.

query: rest/api/2/search?jql=key=MY-1&expand=changelog

in response look at issue->fields[changelog].histories

The date of change is in created field of history item.

If the status was changed the there should be status field listed in items:

Response:

items: [
{
  field: "status",
  fieldtype: "jira",
  from: "1",
  fromString: "Open",
  to: "5",
  toString: "Resolved"
},
{
  field: "resolution",
  fieldtype: "jira",
  from: null,
  fromString: null,
  to: "12",
  toString: "Not a bug"
}
]
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 29, 2013

And the transitions just gives you possible transitions for current state of issue - this is not history of transitions made to issue.

Like Sean Oconnor likes this
Justin Ellis August 29, 2013

I already have changelog expanded; it's in the query I posted in the question. I also already get the status field listed in items that you posted, I pasted that in my question too. What I am *trying* to get is either a timestamp of when the status changed or, alternatively, the amount of time the ticket spent in a particular status. This information appears in the "History" and "Transitions Summary" tabs, I'm asking if it is possible to get it via the REST API.

Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 1, 2013

Right sorry. So the timestamp that you need is, like I said, in created field of history item.

{
  id: "13",
  author: ...,
  created: "2013-06-06T23:12:16.024-0500", 
  items: [
    {
      field: "Attachment",
      fieldtype: "jira",
      from: null,
      fromString: null,
      to: "12",
      toString: "x.png"
    } 
   ]
}

Carolyn Nelson March 18, 2014

Justin, I am trying to do the same thing -- calculate time in status. Did Aleksander's last reply work for you?

Vesa Halkka June 25, 2014

Well.. I have not managed to do this with jira-python yet, but there is an Atlassian service:

https://jira.atlassian.com/plugins/servlet/restbrowser#/resource/api-2-issue-issueidorkey

give it issue-idOrKey JRA-1330 and expand changelog

it will do

https://jira.atlassian.com/rest/api/2/issue/JRA-1330?expand=changelog

changelog starts on line 10776

0 votes
Justin Ellis June 25, 2014

Sorry Carolyn, I never saw your question. Yes, Aleksander's last answer was spot-on. It is not very intuitive, but the "created" field in the expanded histories is the timestamp of the related state change. I was able to get the amount of time that a ticket was in "Open" status, for instance, by looking at the "created" date in the histories for the status change to "Open" and subtracting it from the "created" date in the expanded history for the next status transition.

Suggest an answer

Log in or Sign up to answer