DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Using JIRA's REST API to Create a Dashboard

Using JIRA's REST API to Create a Dashboard

Lorna Mitchell user avatar by
Lorna Mitchell
·
Mar. 28, 12 · Java Zone · Interview
Like (0)
Save
Tweet
10.11K Views

Join the DZone community and get the full member experience.

Join For Free

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();
$request->seturl('https://joindin.jira.com/rest/api/latest/search');
$request->send();
 
$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();
$request->seturl('https://joindin.jira.com/rest/api/latest/search');
$params = array(
    "jql" => "status in (open, reopened)"
);
$request->setquerydata($params);
$request->send();
 
$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)

REST Web Protocols Jira (software) API Dashboard (Mac OS)

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Myths of Kubernetes
  • The Advanced Risk of Basic Roles In GCP IAM
  • Caching Across Layers in Software Architecture
  • How To Use Open Source Cadence for Polling

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo