christaylorcodes / ConnectWiseManageAPI

PowerShell wrapper for the ConnectWise Manage REST API
MIT License
108 stars 61 forks source link

New-CWMTicket always returns an error about insecure redirection #56

Closed CDSFounder closed 2 months ago

CDSFounder commented 8 months ago

I have installed the latest version of ConnectWiseManageAPI module in a Powershell 7.4 environment. I do not have any issues with most of the commands, however the New-CWMTicket command always generates the following error for me:

Line | 40 | … $Result = Invoke-CWMWebRequest -Arguments $WebRequestArguments | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | An error has been thrown. --> --> Cannot follow an insecure redirection by default. Reissue the command specifying the -AllowInsecureRedirect switch. at | Invoke-CWMWebRequest, C:\Users\Chris\<redacted>\Documents\PowerShell\Modules\ConnectWiseManageAPI\0.4.14.0\Private\Invoke\Invoke-CWMWebRequest.ps1: line 45 at Invoke-CWMNewMaster, C:\Users\Chris\<redacted>\Documents\PowerShell\Modules\ConnectWiseManageAPI\0.4.14.0\Private\Invoke\Invoke-CWMNewMaster.ps1: line 40 at New-CWMTicket, | C:\Users\Chris\<redacted>\Documents\PowerShell\Modules\ConnectWiseManageAPI\0.4.14.0\Public\Service\Tickets\New-CWMTicket.ps1: line 328 | at <ScriptBlock>, <No file>: line 1

I have tried: -Closing and re-opening Visual Studio -Disconnect / Reconnect CWM connection -Confirmed that several of the "GET" commands work fine.

This error occurs even when using the minimum required parameters. Example: New-CWMTicket -Summary "test" -company @{id = 19297}

tld6764 commented 8 months ago

I get the same for creating a new company contact.

tld6764 commented 8 months ago

I have found the following:

Parameters -AllowInsecureRedirect Allows redirecting from HTTPS to HTTP. By default, any request that is redirected from HTTPS to HTTP results in an error and the request is aborted to prevent unintentionally communicating in plain text over unencrypted connections. To override this behavior at your own risk, use the AllowInsecureRedirect parameter.

This parameter was added in PowerShell 7.4.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.4#parameters

tld6764 commented 8 months ago

Invoke-CWMWebRequest.ps1...look around the middle (line 45 for me). Update it from: $Result = Invoke-WebRequest @Arguments -UseBasicParsing To the following: $Result = Invoke-WebRequest @Arguments -UseBasicParsing -AllowInsecureRedirect Then close and reload PowerShell and the CW module. That fixed it for me.

christaylorcodes commented 2 months ago

There was an issue with ConnectWise's proxy. Please reopen if this is still an issue.