Add a note to an existing alert in JSM with PowerShell script
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Use this script to add a note to an Opsgenie alert via a POST request, enhancing alert management efficiency.
Solution
The script
// code placeholder
# Variables
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$apiToken = "my-token"
$alertID = "d1a485be-9fcb-4c7e-be0c-ba82667f352f-1745689742269"
$noteText = "This is a test comment , ignore it : V2"# Use the correct endpoint for Opsgenie
$uri = "https://api.opsgenie.com/v2/alerts/$alertID/notes"$headers = @{
"Authorization" = "GenieKey $apiToken"
"Content-type" = "application/json"
}$body = @{
"note" = $noteText
} | ConvertTo-Json$response = Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body $body
Step-by-Step Breakdown
Set Security Protocols
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
Define Variables
$apiToken = "my-token"
$alertID = "d1a485be-9fcb-4c7e-be0c-ba82667f352f-1745689742269"
$noteText = "This is a test comment , ignore it : V2"
$apiToken: Your Opsgenie API key (replace with your actual token).
$alertID: The unique identifier of the alert you want to add a note to.
$noteText: The content of the note you want to add.
Set the API Endpoint
$uri = "https://api.opsgenie.com/v2/alerts/$alertID/notes"
Prepare HTTP Headers
$headers = @{
"Authorization" = "GenieKey $apiToken"
"Content-type" = "application/json"
}
Prepare the Request Body
$body = @{
"note" = $noteText
} | ConvertTo-Json
Send the POST Request
$response = Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body $body
Sends the POST request to the Opsgenie API to add the note to the specified alert.
The response from the API is stored in $response for further use or verification.
Additional Tips
Once you run the script, a Request ID will be generated as output. This Request ID is returned in the API response and serves as a unique identifier for your API request.
You can use this Request ID to check the status of your API operation. Atlassian provides a dedicated endpoint for this purpose:
Simply pass the Request ID to this endpoint to retrieve the current status of your request.
Was this helpful?