Create JIRA Issue with REST API via PowerShell

Ashiquer Rahman Bhuiya November 12, 2023

Getting error. Can anyone help me ?

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

}


$restapiuri = "https://baseurl/rest/api/2/issue"
$headers = Get-HttpBasicHeader "user" "long string"


$body = @"
{
"fields": {
"project": {
"id": "14958"
},
"summary": "Test",
"description": "Test",
"issuetype": {
"id": "3"
},
"reporter": {
"name": "user mail"
}
}
}
"@

 

try {
$response = Invoke-RestMethod -Uri $restapiuri -Headers $headers -Method POST -ContentType "application/json" -Body $body
} catch {
Write-Host "Error: $($_.Exception.Message)"
if ($_.Exception.Response -ne $null) {
$errorResponse = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($errorResponse)
$errorDetails = $reader.ReadToEnd()
Write-Host "Error Details: $errorDetails"
}
}

Error: The remote server returned an error: (400) Bad Request.
Error Details: {"errorMessages":[],"errors":{"reporter":"Reporter is required."}}

1 answer

1 accepted

2 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 12, 2023

Hi @Ashiquer Rahman Bhuiya 

as far as I know the reporter needs to be added with the user‘s id instead of name.

See a similar question in the link below:

https://community.atlassian.com/t5/Jira-questions/How-to-set-reporter-on-an-issue-created-via-Jira-Rest-API/qaq-p/2188822

Best
Stefan

Ashiquer Rahman Bhuiya November 13, 2023

Hi @Stefan Salzl Thanks a lot. It works :)

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 13, 2023

Hi @Ashiquer Rahman Bhuiya 

Awesome. Good to know you got that working 💪💪

Best
Stefan

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events