Have tried the $body_json output in Postman to grab the json data and the Jira is created without issue using the bearer token. I am also able to view a jira using the $headers variable which shows me my authorization is fine. I've tried different error capture methods and all I get back is 400 Bad Status and "ScriptStackTrace : at <ScriptBlock>, <No file>: line 2". I'm not even sure what that means. I've scoured these forums and google and am getting nowhere. Any assistance is much appreciated. Trying to avoid JiraPS module in favor of Invoke-RestMethod for future supportability.
$headers = @{
Authorization = "Bearer mytoken"
"Content-Type" = "application/json"
}
$restapiuri = "https://jira.mydomain.com/rest/api/2/issue"
$body = @{
fields = @{
reporter = @{
name = "myname"
}
project = @{
key = "IT"
}
issuetype = @{
name = "Task"
}
summary = "Test Issue 2"
description = "Detailed description of the issue"
components = @(
@{name = "MyTeam"}
)
}
}
$body_json = $body | ConvertTo-Json -Depth 5
Try{
Invoke-RestMethod -Uri $restapiuri -Method POST -Body $body_json -Headers $headers
}
Catch {
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
}
Here's the json from $body_json
{
"fields": {
"issuetype": {
"name": "Task"
},
"description": "Detailed description of the issue",
"reporter": {
"name": "myusername"
},
"summary": "Test Issue 2",
"components": [
{
"name": "myteam"
}
],
"project": {
"key": "IT"
}
}
}
This returned (201) created in Postman and I verified the Jira was created.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.