Controlapi - 404 Not Found
Closed this issue · 7 comments
In an effort to resolve the index operation bug throwing antiforgery warnings, I pulled the latest master. When that didn't fix it I updated to the below versions:
Automate v20.0.373 (Patch 11)
Automate Control Plugin 6.5.20005.6
Control 20.13.1905.7657
I can login using connect-automateapi, but when I try to login with connect-controlapi I get the below error. This exact URL was working fine before the latest bugs/updates.
Please enter your Control Server address, the full URL. IE https://control.rancorthebeast.com:8040: https://cwa.somedomain.com/connect
Please enter your Control Username: Admin
Please enter your Control Password: **********
Attempt to authenticate to the Control server has failed with error The remote server returned an error: (404) Not
Found.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Connect-ControlAPI.ps1:181 char:21
- ... Throw "Attempt to authenticate to the Control server has ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : OperationStopped: (Attempt to auth...4) Not Found.
:String) [], RuntimeException - FullyQualifiedErrorId : Attempt to authenticate to the Control server has failed with error The remote server re
turned an error: (404) Not Found.
- CategoryInfo : OperationStopped: (Attempt to auth...4) Not Found.
Correct, our Automate and Control are on the same server. Both are listening on 443 for SSL encryption and we used this guide (https://docs.connectwise.com/ConnectWise_Control_Documentation/On-premises/Get_started_with_ConnectWise_Control_On-Premise/Change_ports_for_an_on-premises_installation) to change the URI for Control. Was this a recent change? Because we didn't have any issues using this tool in the previous version.
Can you update Connect-ControlAPI.ps1, around line 80, to be this?
$Server = $Server -replace ':(?<=^https:[^:]+:)443(?!\d)|:(?<=^http:[^:]+:)80(?!\d)|/$', '' #Cleanup URL, remove port specification for standard port values
That's the line that cuts the end off of the URL. If that works I will see about getting it into the main branch.
Here is what I got after making the edit:
Invoke-ControlAPIMaster : An error has been thrown.
at Invoke-ControlAPIMaster, C:\Program
Files\WindowsPowerShell\Modules\automateapi\Public\Invoke-ControlAPIMaster.ps1: line 92
at Connect-ControlAPI, C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Connect-ControlAPI.ps1: line
226
at , : line 1
-->
--> {"errorType":"UnauthorizedAccessException","message":"Invalid anti-forgery token","detail":null}
-----> Use 'Connect-ControlAPI' to set new authentication.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Connect-ControlAPI.ps1:226 char:41
- ... Extension = Invoke-ControlAPIMaster -Arguments @{'URI' = "ReplicaServ ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ControlAPIMaster
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Invoke-ControlAPIMaster.ps1:171 char:46
-
$SCData=$(Try {$Result.Content | ConvertFrom-Json} Catch ...
-
~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFrom
JsonCommand
Control Extension version enabled:
Server version is 20.13.1905.7657.
Successfully tested and connected to the Control API.
And then trying to run the broken agents restart command threw this error:
Get-AutomateComputer -Online $False | Compare-AutomateControlStatus | Repair-AutomateAgent -Action Restart
Checking to see if the recommended Internal Monitor is present
Invoke-ControlAPIMaster : Not connected to a Control server.
----> Run 'Connect-ControlAPI' to initialize the connection before issuing other ControlAPI commands.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Get-ControlSession.ps1:120 char:54
- ... Variables = Invoke-ControlAPIMaster -Arguments @{'URI' = "ReportServi ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ControlAPIMaster
WARNING: Property Name is not supported by this version of Control
WARNING: Property CreatedTime is not supported by this version of Control
WARNING: Property GuestOperatingSystemManufacturerName is not supported by this version of Control
WARNING: Property GuestOperatingSystemName is not supported by this version of Control
WARNING: Property CustomProperty1 is not supported by this version of Control
WARNING: Property CustomProperty2 is not supported by this version of Control
WARNING: Property SessionType is not supported by this version of Control
You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Get-ControlSession.ps1:126 char:73
- ... ssionFields.GetEnumerator(); $IncludeProperty.GetEnumerator() ) | Sel ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (:) [], RuntimeException
- FullyQualifiedErrorId : InvokeMethodOnNull
Invoke-ControlAPIMaster : Not connected to a Control server.
----> Run 'Connect-ControlAPI' to initialize the connection before issuing other ControlAPI commands.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Get-ControlSession.ps1:165 char:24
- ... $AllData = Invoke-ControlAPIMaster -Arguments $RESTRequest
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ControlAPIMaster
Invoke-ControlAPIMaster : Not connected to a Control server.
----> Run 'Connect-ControlAPI' to initialize the connection before issuing other ControlAPI commands.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Get-ControlSession.ps1:191 char:24
- ... $AllData = Invoke-ControlAPIMaster -Arguments $RESTRequest
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ControlAPIMaster
Invoke-ControlAPIMaster : Not connected to a Control server.
----> Run 'Connect-ControlAPI' to initialize the connection before issuing other ControlAPI commands.
At C:\Program Files\WindowsPowerShell\Modules\automateapi\Public\Get-ControlSession.ps1:210 char:28
- ... $AllData = Invoke-ControlAPIMaster -Arguments $RESTRequest
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-ControlAPIMaster
No Input Objects could be processed
Ahh... Ok.. Now that the URL has the extra stuff, the Origin header isn't clean.
Replace the next line with this:
$testCWCHeaders = @{'Origin'=$Server -replace '/(?<=://.+).*$',''}
I am a little concerned that your result showed:
Successfully tested and connected to the Control API.
When it definitely didn't connect successfully.... I might need to check that closer.
Success! I'll go ahead and close the issue. Thank you for your assistance.
Control Extension version 4.1.0.3 enabled: True
Server version is 20.13.1905.7657.
Successfully tested and connected to the Control API.
The official branch now includes the fix.