Over a million developers have joined DZone.

Using JIRA's REST API to Create a Dashboard

DZone's Guide to

Using JIRA's REST API to Create a Dashboard

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

If you read this blog often, you'll know that I am:

  • crazy about APIs
  • living with some accessibility issues

Put these two things together and what do you get? Actually don't answer that! Today what you get is an example of integrating with JIRA's REST API, because their recent "upgrade" locked me out of the issue listings pages completely and I really do need to be able to see a list of bugs! Their bug editing screen is quite usable, so it's just the list that I need here, but you could easily call their other API methods as you need to.

These examples are PHP and use the PECL_HTTP extension, because it's awesome, but these examples could be easily adapted to use another language or library.

What's The REST URL?

We have hosted JIRA from Atlassian, which I think is now called Jira Studio, because they give free pretty-much-unlimited licenses to open source projects, and for that I don't think I'll ever be able to thank them enough. Not enough organisations recognise the value of open source!

Our "normal" JIRA URL: http://joindin.jira.com.

The URL to access the RESTful service: https://joindin.jira.com/rest/api. Note this requires SSL.

Getting a List of Issues

This should be easy, but many services make it hard. Not this one, here's my code:

$request = new HttpRequest();
$issue_list = json_decode($request->getResponseBody());

Now I have all the issues in $issue_list - this is paginated, you can control how many issues you get in a list; the default is 50 I think. You can also pass in any search query - basically the same as the search options that you see in JIRA itself. This uses a language called JQL, and you can find some JQL documents here.

I added some parameters to only show me open and reopened issues, so my code sample now looks like this:

$request = new HttpRequest();
$params = array(
    "jql" => "status in (open, reopened)"
$issue_list = json_decode($request->getResponseBody());

This just limits the results to what you're interested in; you could easily add things assigned to yourself, or whatever suits your needs.

Displaying Results

To see what you've got, use print_r on that list of issues! With this information, I made a screen that looks like this (design is not my strong point!):

The simplest is perhaps just to show the code to generate this output - the "Link" actually goes to the web version of the bug since I can easily access that.

foreach($issue_list->issues as $issue) {
    echo "<img src=\"" . $issue->fields->issuetype->iconUrl . "\" alt=\"" 
        . $issue->fields->issuetype->name . "\" /> \n";
    echo "<b>" . $issue->fields->summary . "</b>\n";
    if(isset($issue->fields->assignee->displayName)) {
        echo " (" . $issue->fields->assignee->displayName . ")\n";
    echo "<br />\n";
    echo "<a href=\"http://joindin.jira.com/browse/" . $issue->key . "\">Link</a> \n";
    $updated = new DateTime($issue->fields->updated);
    echo "last updated: " . $updated->format('jS M') . "\n";
    echo "<br />\n";
    echo "<hr />\n";

Since I whipped up this script and will be using it as part of my dashboard of tools, I thought I'd share - I hadn't seen any integration with JIRA before, but atlassian are focusing all their future efforts on this REST service and my first impressions are that it seems pretty good.

(this isn't production code, you probably want to check responses and things before you unpack them, but this got me started and I hope it helps you too)





Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}