Hi,
I'm getting a bad request 400 error when I try to create an issue. I've used postman to test the JSON and that works fine. I've caught the error and I get this:
{"errorMessages":[],"errors":{"summary":"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown.","description":"Field 'description' cannot be set. It is not on the ap
propriate screen, or unknown.","assignee":"Field 'assignee' cannot be set. It is not on the appropriate screen, or unknown.","priority":"Field 'priority' cannot be set. It is not on the appro
priate screen, or unknown."}}
This is my script below. I've changed the credentials etc for privacy.
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
}
$url = "https://URL.com/rest/api/2/issue"
$headers = Get-HttpBasicHeader "username" "password?"
$body = ('
{
"fields":
{
"project":
{
"id": "1234"
},
"summary" : "This is the Summary",
"description" : "This is the issue description",
"issuetype":
{
"id": "3"
},
"assignee":
{
"name": "name"
},
"priority":
{
"id": "5"
}
}
}
')
try{
Invoke-RestMethod -Uri $url -Headers $header -Method Post -ContentType "application/json" -Body $body -Verbose
}
catch
[System.Net.WebException] {$exception = $_.Exception
$respstream = $exception.Response.GetResponseStream()
$sr = New-Object System.IO.StreamReader $respstream
$errorResult = $sr.ReadToEnd()
Write-Host $errorResult
}
Thanks
I know this is old, but I have almost the same issue. While debugging my Powershell script I copy my JSON body variable value. I can curl that exact JSON to JIRA API using the same JSESSIONID cookie that my PowerShell script uses and create an issue as intended. Still, for some reason, I get the same error that you are getting when my PowerShell script makes the API request via Invoke-WebResquest and Invoke-RestMethod. I know my Cookie has the proper permissions and the screen has the fields I am trying to populate. Have you solved this problem?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.