Hello ![]()
I am trying to utilize the Jira Cloud API to add an watcher to an issue.
The Jira Cloud platform REST API (atlassian.com)
If i execute this code it add the user that are executing the script as an watcher - just as designed.
$pair = "$($userName):$($userPassword)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
"Accept" = "application/json"
"Content-Type" = "application/json"
}
Invoke-RestMethod -Uri "https://company.atlassian.net/rest/api/2/issue/Key-Number/watchers" -Headers $Headers -Method POST -ContentType "application/json"
But if i add an Body then it fails with an Error 400 - this is the code:
$pair = "$($userName):$($userPassword)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
"Accept" = "application/json"
"Content-Type" = "application/json"
}
$Body = @{
accountId = '123-456-789' #This part is redacted
} | ConvertTo-Json
Invoke-RestMethod -Uri "https://company.atlassian.net/rest/api/2/issue/Key-Number/watchers" -Headers $Headers -Method POST -ContentType "application/json" -Body $Body
If i access the API URL in the browser, this is the output:
I am sure that my body is incorrect - but i cant figure out why.
Could you help?
