I used the below powershell script to create New EPIC Issue . But I am getting error "The remote server returned an error: (400) Bad Request" .
This same script is working fine for creating Task , Story and Bug , but getting error for EPIC alone .
It will be helpful , if someone can help me out of this .
param(
[string]$username,
[string]$password,
[string]$comment,
[string]$projectkey,
[string]$summary,
[string]$description,
[string]$issuetype
)
function ConvertTo-Base64($string) {
$bytes = [System.Text.Encoding]::UTF8.GetBytes($string);
$encoded = [System.Convert]::ToBase64String($bytes);
return $encoded;
}
function Get-HttpBasicHeader([string]$username, [string]$password, $Headers = @{}) {
$b64 = ConvertTo-Base64 "$($username):$($Password)"
$Headers["Authorization"] = "Basic $b64"
$Headers["X-Atlassian-Token"] = "nocheck"
return $Headers
}
function add_comment([string]$issueKey,[string]$comment) {
$body = ('{"body": "'+$comment+'"}')
$comment=(Invoke-RestMethod -uri ($restapiuri +"issue/$issueKey/comment") -Headers $headers -Method POST -ContentType "application/json" -Body $body).id
return $comment
}
function transition([string]$issueKey,[string]$transitionid) {
$body = ('{"transition": "'+$transitionid+'"}')
$comment=(Invoke-RestMethod -uri ($restapiuri +"issue/$issueKey/transitions?expand=transitions.fields") -Headers $headers -Method POST -ContentType "application/json" -Body $body).id
return $comment
}
$restapiuri = "https://<organization>/rest/api/2/issue"
$headers = Get-HttpBasicHeader "Username" "Password"
$payload = @{
fields= @{
project= @{
key= "key"
};
summary= "summary"
description= "description"
issuetype= @{
id= "Epic"
}
}
}
$jsonpayload = $payload | ConvertTo-JSON
Invoke-RestMethod -uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $jsonpayload