how to create a JIRA ticket using Powershell code example

Example: how to create a JIRA ticket using Powershell

[Reflection.Assembly]::LoadFile("C:\myAssemblies\ChilkatDotNet2.dll")

$rest = New-Object Chilkat.Rest

#  URL: https://your-domain.atlassian.net/rest/api/2/issue
$bTls = $true
$port = 443
$bAutoReconnect = $true
$success = $rest.Connect("your-domain.atlassian.net",$port,$bTls,$bAutoReconnect)
if ($success -ne $true) {
    $("ConnectFailReason: " + $rest.ConnectFailReason)
    $($rest.LastErrorText)
    exit
}

$rest.SetAuthBasic("[email protected]","JIRA_API_TOKEN")

$json = New-Object Chilkat.JsonObject
$json.UpdateString("fields.project.id","10000")
$json.UpdateString("fields.summary","something is wrong")
$json.UpdateString("fields.issuetype.id","10000")
$json.UpdateString("fields.assignee.name","matt")
$json.UpdateString("fields.priority.id","3")
$json.UpdateString("fields.labels[0]","bugfix")
$json.UpdateString("fields.labels[1]","blitz_test")
$json.UpdateString("fields.description","description")
$json.UpdateString("fields.fixVersions[0].id","10001")
$json.UpdateString("fields.customfield_10005","blah blah")

$rest.AddHeader("Content-Type","application/json")
$rest.AddHeader("Accept","application/json")

$sbRequestBody = New-Object Chilkat.StringBuilder
$json.EmitSb($sbRequestBody)
$sbResponseBody = New-Object Chilkat.StringBuilder
$success = $rest.FullRequestSb("POST","/rest/api/2/issue",$sbRequestBody,$sbResponseBody)
if ($success -ne $true) {
    $($rest.LastErrorText)
    exit
}

$respStatusCode = $rest.ResponseStatusCode
if ($respStatusCode -ge 400) {
    $("Response Status Code = " + $respStatusCode)
    $("Response Header:")
    $($rest.ResponseHeader)
    $("Response Body:")
    $($sbResponseBody.GetAsString())
    exit
}

$jsonResponse = New-Object Chilkat.JsonObject
$jsonResponse.LoadSb($sbResponseBody)

$id = $jsonResponse.StringOf("id")
$key = $jsonResponse.StringOf("key")
$self = $jsonResponse.StringOf("self")

Tags:

Misc Example