SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
ASP.NET, VB.NET, Microsoft .NET Framework, Microsoft Visual Studio, Windows Forms, Controls and more Tutorials and Articles for Programmers

Jira Integration in VB.NET using REST API Methods to Search Jira Issues

In this .NET Framework tutorial, I want to show how Jira Integration can be done using REST API calls with HTTP WebRequest objects in a sample project. In short JIRA APIs are used to query Jira issues. Web service is called using HTPP GET method and JSON response of the API call will be fetched.
Using SQL Server 2017, programmers can use new JSON support features of SQL Server data platform to parse JSON response from the REST API calls.

What is JIRA software?

JIRA is a software used for project management and especially for issue tracking by project teams who prefer agile methods for managing project. Please visit to Atlassian for more official information about Jira software and its usage as a project management tool and its capabilities for integrating to other well-known software development tools.

I have been using JIRA as a tool for managing agile project sprints, issues and backlog items, etc within the agile project teams. HP Service Manager (HPSM) can be integrated with Jira using REST API provided for JIRA Server Platform.

This tutorial is created after an application is created to fetch Jira issue tracking data for defining and measuring KPI figures for agile teams working with JIRA tool.

JIRA REST API Methods to Query Issues for a Project

Atlassian provided a REST API for developers who are responsible for integrating Jira with other tools like HPSM, Bitbucket, Bamboo, etc. Developers can refer to JIRA REST API reference for complete list of API methods and how to use them.

VB.NET codes that I share in this tutorial shows how programmers can query JIRA issues for a specific project using SEARCH API method.

If you read the above Search API documentation, a jql parameter which is a JQL expression is passed to the API method via URL.
The JQL expressions can simply be formed and viewed at Seach page that can be launched by following SDD: Issuetracker > Issues > Search for Issues menu options.

open search for issues page to build jql query on JIRA

For example, using Search a JIRA user can build own custom JQL query (Jira Query Language) to filter required issues as a list.
As an exemple, following jql is build for listing jira issues of a specific project that are updated since the beginning of week.

search JIRA issues on SDD IssueTracking portal using JQL

On Search page, an SDD user can build the jql expression to search Jira issues. After the execution of the JQL search filter if you check the URL of the browser, you will be able to get the URL address that can be called via get method of the REST API Search method.

https://issuetracking.kodyaz-sdd.com/issues/?jql=project = "ART@S4" AND updatedDate >= "2018-12-20" ORDER BY updated ASC&startAt=1&maxResults=5

Note for the programmer: Although updatedDate is a not valid parameter for the issue search method, updated date can be passed to the Search method as a filtering criteria within jql query. Search method returns all issues by checking the updated date value of the issues defined in jql query string. All other valid request parameters used for the JQL can be found in the API method documentation.

To fetch all issues for a specific project following jql expression can be used passing the project name in jql and other parameters in the query string as follows:
HTML query string parameters as: jql=project="ARTS@S4"&startAt=1
In your coding, you can build your URL simply by concatenating query parameters and their values. And then you convert it using HTML encode.
The project name of the Jira issues that are created under, for pagination starting from 1 with max results of 5 issues

Let's see how VB.NET code can be implemented to call SDD Rest API Search method using above JQL oarameter

First of all, .NET Framework developers require two namespaces System.Net for authorizations and System.IO for working with Search API JSON response
So add following "Imports" code lines at the beginning of your program

Imports System.Net
Imports System.IO

Following code block builds the URL that will be called for REST API Search method.
The JQL query is formed and attached to the tail of the API method URL.
Of course, developers can modify below code and turn it into a more generic and dynamic way according to their requirements.

Dim sURL As String
sURL = "https://issuetracking.kodyaz-sdd.com/rest/api/2/search?jql="
sURL &= "project = 'ART@S4'"
'sURL &= " AND updatedDate >= '2018-12-20' ORDER BY updated ASC"
sURL &= "&startAt=1"
sURL &= "&maxResults=5"

If you want to add last updated date as a parameter then the developer can uncomment commented code line for dates and sort order of the JIRA issues returned

Then we are ready to create the WebRequest object using the URL address formed in previous step.

' Create Web Request
Dim objWebRequest As WebRequest
objWebRequest = WebRequest.Create(sURL)

If the developer is running this code to call Search method behind an internet proxy, then below code will be required to authenticate at the proxy server.
Please note, all given information is some dummy data to make the code more understandable for the developer.

' Proxy Authentication
Dim user As String = "TR\\KODYAZ" ' Domain user
Dim password As String = "KodyazPwd" ' Domain password
Dim myProxy As New WebProxy("proxy.kodyaz.com:8080", True)
myProxy.Credentials = New NetworkCredential(user, password)
objWebRequest.Proxy = myProxy

SDD or JIRA portal requires basic authentication and the developer who is making the REST API Search method call.
Programmer can get this header information using for example, REST Console application on a Chrome browser.

' Basic Authentication on Remote Web Site
objWebRequest.Headers.Add("Authorization: Basic TXHhaHBlbi3ZaXytNXo5QWSeNjM7NKL=")

Programmer is now ready to send the request and get the response of the API call.
Following VB.NET code shows how the JSON response of the JIRA REST API call can be fetched using Stream object.

' Get Response
Dim objStream As Stream
 objStream = objWebRequest.GetResponse.GetResponseStream()
Catch ex As Exception
End Try

In the following code, top 5 JIRA issues are read using Search API and output response in JSON format is displayed on the console.

' Display API Query Results
Dim i As Integer = 0
Dim sLine As String = ""
Dim objStreamReader As New StreamReader(objStream)

Do While Not sLine Is Nothing
 i += 1
 sLine = objStreamReader.ReadLine
 If Not sLine Is Nothing Then
  Console.WriteLine("Line {0}: {1}", i, sLine)
 End If

Of course instead of writing the API response on the Console, the .NET developer can parse the JSON string using VB.NET code or pass the string value as an input paraneter to a SQL Server database procedure and parse the JSON string using SQL Server 2017 JSON support.
Please refer to SQL Server tutorial showing how to parse JSON string using OpenJSON on a sample web service response from AWS.

And for Microsoft .NET Framework developers, I have copied a screenshot of the codes I have developed for querying SDD Issue Tracking portal for JIRA issues list. As a programmer, the VB.NET code is not complex. The only thing to take care is choosing the correct JIRA REST API for solution of your requirements.

call REST API Search method to list JIRA issues

I hope this programming tutorial helps .NET developers who are working on JIRA integration projects by calling REST APIs published by Atlassian.

One last note for developers, if you are interested in certain fields in the result set of issue search list, you can find the labels and mapped fields names when you export an JIRA issue to XML on IssueTracker software.

For example on JIRA IssueTracker open an issue, click on Export button and choose XML as target format

export Jira issue to XML

In the exported XML data of the issue, you can search for values displayed on the web GUI. For example, I found that sprint data of which the issue is assigned is stored in field customfield_10000, etc. Using this information, the API developer can query issue list for a project and store or check specific values of each issue.

Jira issue data mapping in XML

Visual Studio

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.