Unexpected Error on sis-import (PowerShell)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021
09:21 AM
With the code below attempting to send a zip file to the sis_imports API, I am getting a PowerShell error, "Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send."
$URL = "https://$APIDomain/api/v1/accounts/1/sis_imports"
$headers = @{"Authorization"="Bearer "+$Token}
$InFile = $ZipDestinationFull <# path to zip file #>
$contentType = "application/zip"
Invoke-WebRequest -URI $URL -Headers $headers -Method POST -InFile $InFile -ContentType $contentType
Any idea what I'm missing?
Note, the code seems to work for PowerShell 7, but not PowerShell 5 (the version that my institution uses).
Solved! Go to Solution.
Labels (7)
Labels
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2021
10:12 AM
I found a solution. It apparently has to do with a TLS compatability issue.
Source: https://blog.darrenjrobinson.com/powershell-the-underlying-connection-was-closed-an-unexpected-error...
Solution:
Insert the following line before invoking your PowerShell WebRequest using either Invoke-RestMethod or Invoke-WebRequest.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12