How to get details from database and create the new issue on jira using jiraPS

Praveen K L September 20, 2023

I am trying to intergrate database (MS-Sql) and jira to raise a issue on jira using JiraPS but I don't know where to start. Any solution for this.  

1 answer

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2023

Hello @Praveen K L 

Welcome to the Atlassian community.

Can you describe your scenario in more detail? How are you trying to integrate your database and Jira? What is the flow of events that would lead to an issue being created in Jira?

Praveen K L September 20, 2023

Thanks @Trudy Claspill Yeah sure.

I have created a database with field inputs like Plugin I'd, Plugin family and few more columns. Now we have to create an issue with these field inputs to be inserted in Jira issue while creating issue.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 22, 2023

What is your level of experience with Powershell?

Are you trying to figure out how to get the data from your database?

Are you trying to figure out how to use the JiraPS module itself just to interact with Jira?

Praveen K L September 22, 2023

Hi @Trudy Claspill 

Without JiraPS, I have tried to create issue using the rest api but that gives a 400 bad gateway error. 

Code for you reference,

$JiraUrl = "https://my jiraurl/rest/api/2/issue"
$ApiToken = " apitoken"
$Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(maild:$ApiToken))

$IssueData = @{
"fields" = @{
"project" = @{
"key" = "TEST"
}
"summary" = "This is issue summary"
"description" = "This is the issue description"
"issuetype" = @{
"name" = "Incident"
}
}
}

$RequestBody = $IssueData | ConvertTo-Json

$Response = Invoke-RestMethod -Uri $JiraUrl -Headers @{
Authorization = "BASIC" + $Base64AuthInfo
} -Method Post -ContentType "application/json" -Body $RequestBody

* I am new to both the technology, trying to learn new things. I was unable to figure out the exact reason for 400 bad gateway error. So if the rest api code works fine we can use Rest api for database integration.

Note: JiraPS code is working fine for me.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2023

If the JiraPS code is working for you, then what exactly is your question?

Praveen K L September 23, 2023

Well my question is 

* To create a issue getting the inputs from the database and attach some inputs in work notes.

* This shall be done using JiraPS.

Request from my side, If possible kindly troubleshoot the rest api method so that it can be helpful for me.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 24, 2023

Regarding your API issue, HTTP error code 400 is "bad request" not "bad gateway". Those are two very different errors. Which one are you actually getting.

Regarding extracting data from your separate database to use as input to Jira, you won't code that interaction using either the Jira REST API or the JiraPS module. That code is for interacting with Jira, not for interacting with databases. You will need to use other code, either Powershell or the programming language you are using to write the Jira REST API commands, to interact with your database to extract the data from it, and then use that as input to the Jira commands.

You said the JiraPS code is working fine for you. Does that mean you have successfully created a Powershell script with that module and have been able to successfully connect to your Jira instance and create an issue through Powershell code?

Praveen K L September 25, 2023

* This code returns this following error.

$JiraUrl = 'https://myjiraurl/rest/api/2/issue'
$ApiToken = 'my api token'
$header = @{
Authorization = 'Basic ' +
[Convert]::ToBase64String(
[Text.Encoding]::UTF8.GetBytes("mymailid:$ApiToken")
)
}

$IssueData = @{
Project="TES"
IssueType="[System] Incident"
Summary = "Powershell created support request summary"
Description = "Some description"
} | ConvertTo-Json

Invoke-RestMethod -Uri $JiraUrl -Method Post -Headers $header -Body $IssueData

The above code returns this error

Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.
At line:17 char:1
+ Invoke-RestMethod -Uri $JiraUrl -Method Post -Headers $header -Body $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebE
xception
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

* The JiraPS code which creates the issue from Powershell, working fine without any error.

Set-JiraConfigServer 'https://myjira url'
$password = ConvertTo-SecureString 'my api token' -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("my mailid",$password)
New-JiraSession -Credential $creds
New-JiraIssue -Project "TEST" -IssueType "[System] Incident" -Summary "Created using powershell" -Description "Working Fine"

Praveen K L October 17, 2023

Hi @Trudy Claspill 

Any update on the above code.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events