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
Welcome to the Atlassian Community!
The 400 response is coming from the web server (probably a proxy between you and Jira), and your powershell script is not giving you the actual message that Jira has responded with.
My best guess from your code and description that other issue types work is that you are not giving Jira all the data it needs to create an Epic. Epics require the field "epic name" to be filled in. I suspect if you read the full response, it would contain "Epic name is a mandatory field"
I just stuck where i could i make these changes . It will be helpful ,if You show the changes to be made in my code. You can re-share the updated code .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know enough powershell to write with any confidence, but if it is just the epic name you're missing, the pseudo code you need to implement comes out as
If (issuetype == Epic) then
Epic Name = "an epic name" (a lot of us would simply repeat the summary field when automating this)
Send Epic name along with the other fields
fi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It will be helpful, if someother could sort this and share updated script .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.