Search code examples
restjiradashing

Get useful information about a JIRA board using the REST API


I've been digging around documentation for JIRA's latest REST API (6.0.1) to try and dig out information about a particular dashboard (I'm playing around with Dashing to create a widget displaying the number of open issues in a particular sprint). According to this:

https://developer.atlassian.com/static/rest/jira/6.0.1.html

jira.com/rest/api/2/dashboard/11311 will only give me something like:

{
  "id": "11311",
  "name": "blah",
  "self": "jira.com\/rest\/api\/2\/dashboard\/11311",
  "view": "jira.com\/secure\/Dashboard.jspa?selectPageId=11311"
}

which doesn't exactly give me a lot of information.

In greenhopper times, we could get more useful information with something like:

/rest/greenhopper/1.0/xboard/work/allData.json?rapidViewId=#{board_id}"

(Taken from here) but that seems to not work now..Any ideas if there's another endpoint which might return more information?


Solution

  • I managed to do it via a jql query. '914' is the agile board ID (a neat way to find this is checking the last digits of the 'Report' URL of the board)

    SCHEDULER.every '5s', :first_in => 0 do |job|
     uri = URI.parse(jira_url)
     http = Net::HTTP.new(uri.host, uri.port)
     req = Net::HTTP::Get.new("/rest/api/2/search?jql=sprint%20%3D%20914%20AND%20status%20%3D%20%27In%20Progress%27")
     req.basic_auth username, password
     response = http.request(req)
     issuesinProgress = JSON.parse(response.body)["total"]  
     send_event('buzzwords', value: issuesinProgress)
    end
    

    This is a very useful tool to encode your query into urlencode.

    sprint = 914 AND status = 'In Progress' encodes to sprint%20%3D%20914%20AND%20status%20%3D%20%27In%20Progress%27