Retrieving And Filtering JIRA Issue Views Through Request URL

      When developing a JIRA gadget for the WSO2 Gadget Server i found out that some aspects of the JIRA facilities are not well documented. This post will try to help with one such not-well documented service provided by Atlassian JIRA.
      In my gadget i had to filter the data that i needed according to several parameter that would vary from request to request.I decided to use "searchrequest-xml" that is provided by Atlassian JIRA this can be accessed by a simple URL and can also be filtered using parameters in the URL. This will return a XML containing the data that was requested. How the parameters should be defined to filter the request is not clearly documented. The aim of this post to provide a brief documentation as to how the parameters can be set for the "searchrequest-xml" URL request.

What You Need To Know
    The things given below are not that necessary to understand this post as the purpose of the post is to document the format of the "searchrequest-xml" URL. But if you are trying to use this feature (preferably in a gadget) you probably will have some knowledge of list below 
  1. Google Gadgets and the API 
  2. JavaScript
  3. XML
  4. Atlassian JIRA
Getting Started
    What we are trying to accomplish is to retrieve JIRA issue data to be used in our JIRA gadget.Data can be retrived as a xml using the following URL
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchXML.xml
   This is retrieves all the data related to the organization. It is better if we can retrieve only the data that we need to get by specifying certain parameters with this URL.Here "SearchXML" can be any name you like.


  • Filtering by project
    • You can filter the XML by giving an project id. For example if we are to retrieve the data that is related to the project with project id "ABC" the URL will be as follows.
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchXML.xml?pid=ABC


  • Restricting the maximum number of items return
    • This can be done by using the parameter "tempMax". the following example will only retrieve the first 10 results of the filter.    
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchXML.xml?pid=ABC&tempMax=10


  • In the same manner the following parameters can be also used to filter the data.
    • issuetype: eg- issuetype=BUG
    • priority: eg- priority=HIGH
    • resolution: eg-  resolution=Unresolved
    • status: eg- status=Open
    • repoter
    • assignee
  •  Searching 
    • This URL can also be used to search the content of the issues and find the related issues for a search query.below is the format of the search query.
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/vvdfv.xml?pid=ABC&query=build&summary=true&environment=true&body=true&tempMax=3
              The above URL searches the XML for the word "build" and it looks in environment, comments and summery. Here the param "query" specifies the string to be searched and you can set where you want to search by setting body=true to search in comments.Likewise you can set environment,summery and description true if you want to search them also.

  • Paging 
    • Parameter can be set to do paging for the request. As shown in the following URL 
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/vvdfv.xml?pid=OZONE&type=Bug&priority=Highest&tempMax=2&pager/start=2
      Here the link retrieves two items from the XMLand it starts with the second item so this can be used to page the request by generating the request URL correctly

  • Searching by dates
    • The request can be also filtered by related dates.As given by the following URL  
https://yourcompany.org/jira/sr/jira.issueviews:searchrequest-xml/temp/vvdfv.xml?pid=GS&created:after=2010/02/12&created:before=2010/12/02&tempMax=3
        This searches for related issues created after 2010/02/12 and before 2010/12/02.the following formats can be used to specify dates.

    • yyyy/MM/dd HH:mm', 'yyyy-MM-dd HH:mm', 'yyyy/MM/dd', 'yyyy-MM-dd or as DD/MMM/YYYY

     This is only a small amount of parameter that i came across. There are many other below are the

  • assigneeSelect
  • created:after
  • created:before
  • created:next
  • created:previous
  • description
  • duedate:after
  • duedate:before
  • duedate:next
  • duedate:previous
  • pid
  • query
  • refreshFilter
  • reporter
  • Selectreset
  • Update
  • resolutiondate:after
  • resolutiondate:before
  • resolutiondate:next
  • resolutiondate:previous
  • showView 
 Discovering On Your Own
     I have not listed all the options that are available in the post there are many other parameters that can be specified. And it is not that hard to figure out how to specify them and what they do. What i did was use the search options given in the dashboard and specifiy a search critiera the link for the search criteria can be found from the permanent link that is in the top right coner of the page. use a little bit of Firebug and you will be able to figure out what you need in no time
Note: Firebug is a Firefox extension that can be used for many purposes in this context it can be used to view the request and response headers.

Example code 
  Lets look at a small example. The following code snippets are part of a gadget description XML and uses the Google Gadgets JavaScript API. This example will demonstrate how to make a search request to JIRA and how to retrieve data.
function makeXMLRequest(){
var params = {};
var prefs=new gadgets.Prefs();
var url= prefs.getString("feedurl");
      params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.XML;
     
       gadgets.io.makeRequest(url,processXML, params);
}
function processXML(obj) {

      var xmldata = obj.data;
          document.getElementById('content_div').innerHTML = obj.text;
};
  

    Here the UserPref  "feedurl" holds the request URL that is made according to the format described above 

Comments

  1. thank you. but how do you log in?

    ReplyDelete
    Replies
    1. I am not sure what you mean by log in here. but to access data it is not required to log in for example try this.

      https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchXML.xml?pid=PIG&tempMax=10

      If you want to authenticate the user and retrieve user specific data i think you have to use OAuth. I haven't worked with authentication.

      Delete
    2. JIRA also supports a REST API and a XML_RPC API as far as i know :). These API's might provide what you are looking for.

      Delete
  2. If you want to add login details to the url, try adding this:

    "&os_username=&os_password="

    ReplyDelete
  3. This phrase suggests a process or task related to working with Jira, a popular issue tracking and project management tool.
    Why Online Games It likely involves the retrieval and selection of specific issues from Jira's database.

    ReplyDelete

Post a Comment

Popular posts from this blog

Setting up Heron Cluster with Apache Aurora Locally

Reading and Writing Binary files in java - Converting Endianness ( between Big-endian byte order and Little-endian byte order)

Writing Unit Tests to test JMS Queue listener code with ActiveMQ