Using JIRA API in R

Recently at work, a problem with reading data from JIRA via R came up and I thought I would write up some of my thoughts about it here.

For those of you who aren’t familiar with API, it stand for Application Programming Interface and most websites have some form of API. You can use API to directly talk to a server.

In this specific post, I want to talk directly with the JIRA servers. If you are reading this post then you are probably already familiar with JIRA but it you aren’t, it is essentially a software provided by Atlassian for “agile teams”. Putting aside my feelings about the overuse of terms agile and teams together, let’s dig into the API.

Atlassian does actually provide a page on JIRA API.

The REST here means Representational State Transfer, which really is just fancy language describing the architectural style of the API. If you want to learn more about REST I recommend looking it up as I won’t go in more detail about it here.

Now, there are several ways to pull data into R using JIRA API (curl, GET, etc.). In this particular example I will use GET.

library(httr)

# Using URI path for JIRA's public issue tracker
json <- httr::GET("http://jira.atlassian.com/rest/api/latest/issue/JRA-9")

I like using GET because I do have the option of using a username/password to authenticate access built in to the function. For obvious reasons though you should avoid hardcoding username/password information into your code. If you are having trouble finding your company/institute’s specific URI path, you will want something like this:

http://host:port/rest/api/2

OR

http://host:port/rest/api/latest

You can also specify if you want to look up a specific project and how many results (JIRA API will automatically restrict you to 50 issues but you can overwrite this default).

http://host:port/rest/api/latest/search?jql=project="Project Name"&maxResults="num of Results you want to limit to"

Just make sure to replace the "Project Name" and "num of Results you want to limit to"
(including the quotes) with the appropriate inputs

And viola, you have use JIRA API to bring data from JIRA into R. Probably right about now you are asking yourself, “Wait a minute, what is this? How am I suppose to use this?”. What you are looking at is JSON (JavaScript Object Notation) data. Unfortunately, pretty much whenever you use API you will get JSON data. And frankly, as someone in analytics, I find it an awful format. While I understand there are some benefits to using it (lightweight format, easy to parse/generate, etc.), I like working in data frames and data tables. Which means the rare moments I do encounter JSON, it is the bane of my exist.

My following post will be on what are some of the best ways to try to convert the JSON data into a usable data frame.

EDIT: I’ve reviewed this post and found that the links I originally provided for username and password authentication are not the most helpful. I’ve updated accordingly and provided an example below.

query <- httr:GET("http://host:port/rest/api/latest/search?jql=project="Project Name"
    &maxResults="num of Results you want to limit to"", authenticate("username","password","basic")

Obviously, it isn’t a great idea to hardcode a password and username into your code. I would recommend only using this method if you are prompting the user for username and password input to use in this query (and not actually saving the input). If you need more ideas on how to use password authentication with JIRA API I would recommend checking the following post:

https://community.atlassian.com/t5/Jira-questions/Passing-username-and-password-via-URL-to-jira/qaq-p/16679