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)

------------------------------ Scenario 1: ------------------------------
Pros: simple implementation, examples on the supplier’s website.
Cons: 30 day TRIAL. Paid access later.

UiPath Studio with additional packages in project:
Chilkat .NET Class Library (x86) [chilkat-win32: ver. > = 9.5.0.83] or
Chilkat .NET Class Library (x64) [chilkat-x64: ver. > = 9.5.0.83]
Microsoft.AspNet.WebApi.Client
UiPath.WebAPI.Activities
System.Net.Http

Manage Packages View

Remember to add set of namespaces to Project Imports:
image

List of Namespace in Imports

Thanks to the possibility of building an API query based on the Chilkat library, we can provide credentials in the form of user login and password for Jira.

Examples of using JIRA on-prem with the Chilkat library can be found here:
Main Site of examples: http://rest-examples.chilkat.io/default.cshtml
Sub-sites:
Jira Issues
Jira Project
Jira Schemes
Jira User

Sample VB.NET Code for JIRA Create Issue (POST API):

Sample VB.NET Code View

We process the response on JSON Object and extract the data we are interested in.

Important:
Jira supports the day format as standard ISO 8601. In UiPath Studio we need changing the ISO 8601 date notation from: 2011-12-13T14:30:00.000+02:00 to: 2011-12-13T14:30:00.000+0200
(removing the last colon from offset) with is accepted by JIRA.

Code for change notation: DateTime.ParseExact(in_errorDate,"MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString(dateFormat).Remove(26, 1)

Available workflows:
Jira_GET_Issue.xaml
Jira_GET_Issue_Fields.xaml
Jira_GET_Issue_Transitions.xaml
Jira_POST_Create_Issue.xaml
Jira_POST_Issue_Add_Comment.xaml
Jira_POST_Issue_Transitions.xaml
Jira_PUT_Assign_Issue.xaml

Use UiPath Project: API_JIRA_on_prem_UiPath.7z (20,8 KB)

------------------------------ Scenario 2: ------------------------------
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).

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:

'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

Source Code

----------------------Source Code:----------------------
'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:

'Create a new HTTP request
Dim client As HttpClient = New HttpClient()

Source Code

----------------------Source Code:----------------------
'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----------------------

6 Likes

:+1: