How to POST minified js-file and source map to Raygun's source map API endpoint via Windows Powershell script?


Posted on
Nov 11 2016

Our company is trying to post my minified filename.js and files to Raygun's Js source center via Powershell script. To do that I applied the instructions provided here: However, I couldn't get it working. The server just returns 400 Bad Request when I run the script. What am I missing/doing wrong here?

Here's the powershell script I used to try to send the minified js-file:

$uri = ''
$file = Get-Item C:\path\to\my\filename.js
$body = @{
    url = 'https://localhost/MyAppName/js/filename.js'
    file = $file

try {
    Invoke-RestMethod -Method Post -Uri $uri -Body $body
} catch [Exception] {
    Write-Host $_.Exception

MyAppId and MyExternalAuthToken in the uri are replaced with real ones in the code of course.


Posted on
Nov 11 2016


I believe this should work:

$url = "[ApplicationIdentifier]?authToken=[MyAuthToken]"

$fileUrl = ""
$filePath = "C:\location\of\script.js"
$fileName = "scriptname.js"

$fileBin = [IO.File]::ReadAllBytes($filePath)

$enc = [System.Text.Encoding]::GetEncoding("iso-8859-1")
$fileEnc = $enc.GetString($fileBin)

$boundary = [System.Guid]::NewGuid().ToString() 

$body = (
  "Content-Disposition: form-data; Content-Type: text/html; name=`"file`"; filename=`"$fileName`"`n",
  "Content-Disposition: form-data; name=`"url`"`n",
) -join "`n"

Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType "multipart/form-data; boundary=`"$boundary`""

You will need to update the [ApplicationIdentifier] and [MyAuthToken] in the URL as well as $fileName, $filePath, $fileUrl with your details.

Unfortunately I couldn't figure out any simpler way to do this with powershell.

I'll take a look at putting this example in the documentation too. Let me know if this works for you or if you have any other questions.

Cheers, Alex


Posted on
Nov 12 2016

Great, just tested it and it works perfectly for our purposes. Thank you very much!