Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Alerts API - Add Attachment

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.


1 answer

0 votes
Connor Eyles Atlassian Team Mar 11, 2021

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

$body = $multipartContent

$response = Invoke-RestMethod '' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

Image 2021-03-12 at 3.16.50 pm


Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Opsgenie

Leveraging Atlassian’s Opsgenie and AWS Cloudformation Registry to stay ahead of incidents

In the past, managing IT infrastructure was a hard job. It required a lot of manual effort and it was hard to keep track of all the necessary information (monitoring, scalability etc). Thankfully, as...

1,856 views 0 11
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you