Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,202
Community Members
 
Community Events
165
Community Groups

Getting error "The remote server returned an error: (400) Bad Request" .

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

 

1 answer

1 vote

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 .

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

Like Sivasankaran D likes this

It will be helpful, if someother could sort this and share updated script .

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you