Hi,
I have been trying to use the Jira API to create a ticket and assign a user to it. I can easily create the ticket, add details - description, issue type, summary etc. I can even assign a reporter.
But, when I try to assign an assignee, I get Invoke-RestMethod : {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}
My code is:
$jira_url = 'https://cmcmarkets-sandbox-687.atlassian.net'
$jira_username = '<email address>'
$jira_api_token = '<my personal token>'
$base64_credentials = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($jira_username + ':' + $jira_api_token))
$url_path = '/rest/api/2/issue'
$headers = @{
Authorization = "Basic " + $base64_credentials
Accept = 'application/json'
'Content-Type' = 'application/json'
}
$requestBody = @{
fields = @{
assignee = @{
accountId = "<my accountId>"
}
}
}
$parameter = @{
URI = $jira_url + $url_path + "/<issue Id>/assignee"
Method = "PUT"
Body = ConvertTo-Json $requestBody -Depth 100
}
Invoke-RestMethod @parameter -Headers $headers
I have already collected the Issue ID and my user Id. They are used in place of the markers in the powershell code above.
Now, when I use a similar script, only with slightly different Body parameters, I can create the Issue easily enough. I then get its issue number and try to assign an assignee to it using https://{jira-api}.com/rest/api/2/issue/{issueid}/assignee (with the Body section as shown in the script), as shown in most online documents.
Just keep on getting:
Invoke-RestMethod : {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}
At
\Documents\test\JiraOcto_v03.ps1:136 char:1
+ Invoke-RestMethod @parameter -Headers $headers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Just cannot seem to understand why this error is occurring.