You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Has anyone been able to successfully upload a file to an alert using powershell?
If you have some sample code you could share, I would greatly appreciate it.
I've looked online for similar solutions, but so far nothing has worked.
The file is a text file.
Thanks!!
Hey @Robert Williams
Here is the script on how to do it :)
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "GenieKey xxxxx-xxxxx-xxxx")
$headers.Add("Cache-Control", "no-cache")
$headers.Add("Content-Type", "multipart/form-data")
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$multipartFile = 'test.txt'
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "file"
$fileHeader.FileName = "test.txt"
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$multipartContent.Add($fileContent)
$body = $multipartContent
$response = Invoke-RestMethod 'https://api.opsgenie.com/v2/alerts/673/attachments?alertIdentifierType=tiny' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Thanks,
Connor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.