Hello Atlassian team, I am getting the error of call REST API to Atlassian.
Below is my code to query a ticket with contains a provided keywords. Then these ticket will be closed by transition ID 21
# Replace YOUR_JIRA_URL, YOUR_USERNAME, and YOUR_API_TOKEN with your own Jira URL, username, and API token
$jiraUrl = "https://xxx.atlassian.net"
$username = "xxx@xxx.com"
$apiToken = "xxxxxxxxxxxxxxxxxxx"
# Replace TICKET_NAME with the name of the ticket you want to close
$ticketName = "Scheduled Tasks"
# Set up the base64-encoded credentials for the Jira API
$authInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$apiToken)))
# Set the user agent to a recognizable value
$headers = @{Authorization=("Basic {0}" -f $authInfo); "User-Agent"="Powershell Script"}
# Get a list of all open tickets with the provided ticket name
$response = Invoke-WebRequest -Uri "$jiraUrl/rest/api/2/search?jql=project%20=%20ITENG%20AND%20summary%20~%20'$ticketName'%20AND%20status%20in%20('In%20Progress',%20'Incident%20Reported',%20New)%20order%20by%20created%20DESC" -Method GET -Headers $headers
$results = (ConvertFrom-Json $response.Content).issues
----above code ran well and return all ticket thru $result.-----------
However, I got issue 415 when I ran the REST API below:
foreach ($result in $results) {
# Get the ticket key and id
$ticketKey = $result.key
$ticketId = $result.id
# Set the request body for the transition to the closed state
$requestBody = @{
transition = @{
id = "21"
}
} | ConvertTo-Json
# Perform the transition to the closed state
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$transitionResponse = Invoke-WebRequest -Uri "$jiraUrl/rest/api/2/issue/$ticketKey/transitions" -Method POST -Headers $headers -Body $requestBody
Write-Output $transitionResponse
}
Better late than never, and just in case I forget and run across this again...
You have to have this in the request line:
-ContentType "application/json"
$transitionResponse = Invoke-WebRequest -Uri "$jiraUrl/rest/api/2/issue/$ticketKey/transitions" -Method POST -Headers $headers -Body $requestBody -ContentType "application/json"
FYI: I am running this script with Powershell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.