cancel
Showing results for 
Search instead for 
Did you mean: 
daniel_savlon
Community Participant

Unexpected Error on sis-import (PowerShell)

Jump to solution

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).

0 Kudos
1 Solution

Accepted Solutions
daniel_savlon
Community Participant

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

View solution in original post

1 Reply
daniel_savlon
Community Participant

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

View solution in original post