How to get details from database and create the new issue on jira using jiraPS
Asked by Praveen K L:

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.


Answers:
author: Trudy Claspill
body: Hello [@Praveen K L](/t5/user/viewprofilepage/user-id/5319525)

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?

comments: author: Praveen K L
body: Thanks [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011) 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.


author: Trudy Claspill
body: 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?


author: Praveen K L
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

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.


author: Trudy Claspill
body: If the JiraPS code is working for you, then what exactly is your question?


author: Praveen K L
body: 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.


author: Trudy Claspill
body: 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?


author: Praveen K L
body: \* 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"


author: Praveen K L
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

Any update on the above code.


Tags: cloud

jira-software

jira-software-cloud