LabtechConsulting / ConnectWise-Manage-Powershell

This is a PowerShell wrapper for the ConnectWise Manage REST API.
http://labtechconsulting.com
34 stars 19 forks source link

Error when trying to connect to Cloud server. #17

Open jcandresen opened 4 years ago

jcandresen commented 4 years ago

I'm getting a json error when I try to connect, not entirely sure why.

$Server = 'na.myconnectwise.net'

# This is the company entered at login
$Company = 'ABC'

# Create a credential object
$Credentials = Get-Credential

# Load the module into memory
iwr 'https://raw.githubusercontent.com/LabtechConsulting/ConnectWise-Manage-Powershell/master/CWManage.psm1' | iex

# Connect to Manage server
Connect-CWM -Server $Server -Company $Company -Credentials $Credentials

Connect-CWM -Server $Server -Company $Company -Credentials $Credentials
ConvertFrom-Json : Invalid JSON primitive: Cannot.
At line:792 char:52
+             $global:errDetails = $_.ErrorDetails | ConvertFrom-Json
+                                                    ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand

WARNING: Authentication failed. Clearing connection settings.
andyfeili commented 4 years ago

Connectwise recently updated the API to require an additional header called ClientId

You can create a clientID from https://developer.connectwise.com/ClientID

The readme did not update yet

Use this to connect:

#Public and private key created in connectwise manage
$pubkey = 'XXXXXXXXXXXXXXXX'
$privatekey = 'XXXXXXXXXXXXXXXX'

#ClientID created from https://developer.connectwise.com/ClientID
$clientId = "XXXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXX"

# Connect to Manage server
$Connection = @{
            Server = $Server
            Company = $Company 
            pubkey = $pubkey
            privatekey = $privatekey
            clientId = $clientId
        }
Connect-CWM @Connection
lansalot commented 4 years ago

Nice one, thanks @AndyFeiLi !

Worked for me!