API JIRA ON-PREM (server) - Complete API Solution in VB.NET code for UiPath

Hello,
I present to you below a communication solution through REST API queries to JIRA on-premise (local server in your company) in two variants:

  • Scenario 1: Simple but paid after 30 days trial.
  • Scenario 2: Simple and Free.

I have created 7 files with sample working code.
The activity packages available in UiPath Studio like UiPath.JiraSoftware.Activities
image
are based on cooperation with JIRA Cloud, where you can easily generate an API Token.
The solution below offers ready-made tools for companies that have a server version.

For JIRA automation you will need:

JIRA on-prem (I have version 7.0 Server in my organization) JIRA REST API Reference
JIRA permissions: password and login (as for standard user login)

I currently use these implementation in my JIRA automation. I share 11 source codes in vb.net for Jira with support of HttpClient() class.

Pros: Simple implementation. Free solution.
Cons: Requires creating an additional module to convert Jira fileds to JsonString, Example here: How do I create JSON Object from Dictionary(String, String) - #9 by Adrian_Star.

UiPath Studio with additional packages in project:
Microsoft.AspNet.WebApi.Client: 5.2.7,
System.Net.Http: 4.3.4,
UiPath.WebAPI.Activities: 1.6.0

Manage Packages View

Remember to add set of namespaces to Project Imports:
image

List of Namespace in Imports

Generate token:

Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(String.Format("{0}:{1}", username, password)))

Basic In Aguments:

uri As String = https://jira.example.com/
token As String = eg.:XxxxXxxx==

Basic Out Arguments:

response As System.Net.Http.HttpResponseMessage


Sample VB.NET Code

Jira Create Issue:

Additional in Arguments:
JsonString As String = {"fields":{"mandatory_data"}}

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()
'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage(HttpMethod.Post, "rest/api/2/issue" ) '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Edit Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”
JsonString As String = {"fields":{"mandatory_data"}}

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Put, ("rest/api/2/issue/" +ProjectKey+ ) '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Assign Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Put, ("rest/api/2/issue/" +ProjectKey+ "/assignee") '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Get Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Get, ("rest/api/2/issue/" +ProjectKey) '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Delete Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Delete, ("rest/api/2/issue/" +ProjectKey) '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Get Issue Transitions:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Get, ("rest/api/2/issue/" +ProjectKey+ "/transitions" ) '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Do Issue Transition:

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()
'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Post, ("rest/api/2/issue/" +ProjectKey+ "/transitions" ) '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Get Issue Fields:

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()
'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Get, ("rest/api/2/field") '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Add Comment to Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Post, ("rest/api/2/issue/" +ProjectKey+ "/comment" ) '(Method type, relative access path)

'Body of the query
request.Content = New StringContent(JsonString, System.Text.Encoding.UTF8, "application/json" )

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Delete Comment from Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”
Comment_ID As String = eg. 100234

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

'Specify the target address
client.BaseAddress = New Uri(uri) 'argument IN

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue(“Basic”, token)

'Create query parameters
Dim request As HttpRequestMessage = New HttpRequestMessage (HttpMethod.Delete, ("rest/api/2/issue/" +ProjectKey+ "/comment/" + Comment_ID ) '(Method type, relative access path)

'No Body of the query

'Indicate the service from which to reply to the inquiry
response = client.SendAsync(request).Result
----------------------End Source Code----------------------

Jira Add Attachment to Issue:

Additional in Arguments:
ProjectKey As String = eg.: “ABC-1234”
filePath As String = eg. C:\file\test.jpg
fileName As String = eg. test.jpg
Content_Type As String = MIME type eg. image/jpg

Source Code

----------------------Source Code:----------------------
'Create a new HTTP request
Dim client As System.Net.Http.HttpClient = New System.Net.Http.HttpClient()

'Specify the target address
Dim postUrl As String = uri + "rest/api/2/issue/" +ProjectKey+ "/attachments"
client.BaseAddress = New System.Uri(postUrl)

'Clear header for new iteration
client.DefaultRequestHeaders.Accept.Clear()

'Enter new header parameters
client.DefaultRequestHeaders.Add( "X-Atlassian-Token" , "nocheck" )
client.DefaultRequestHeaders.Accept.Add( New MediaTypeWithQualityHeaderValue( "application/json" ))
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue( "Basic" , token)
'Create query parameters
Dim content As MultipartFormDataContent = New MultipartFormDataContent()

'Body of the query
Dim fileContent As HttpContent = New ByteArrayContent(File.ReadAllBytes(filePath))
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(Content_Type)
content.Add(fileContent, "file" ,fileName)

'Indicate the service from which to reply to the inquiry
response = client.PostAsync(postUrl, content).Result
----------------------End Source Code----------------------

8 Likes

:+1:

Can you able to update the package for windows compatibility.