For something so seemingly simple I'm having no luck updating JIRA issues via the REST API.
Has anyone been able to update JIRA issues using Powershell? I've pretty well exhausted all the options on stackoverflow and atlassian's website.
No scripts for curl, invoke-restmethod or invoke-webrequest have done anything but returned errors.
Retrieving info from the issue is not a problem. Changing it... holy cow.
I'd be immensely grateful if someone could help me find a way to solve this.
Thanks!
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
}
$restapiuri = "https://jira.server.com/rest/api/2/"
$headers = Get-HttpBasicHeader "user" "password"
add_comment "MyIssue-1234" "[~test.user] please handle the issue."