sgtoj / PSConnectWise

PowerShell Module that provide several CmdLets to interact with ConnectWise REST API service.
MIT License
45 stars 13 forks source link

Upcoming breaking change to the connectwise Rest API. #50

Open TheSystech opened 5 years ago

TheSystech commented 5 years ago

They will start requiring a generated GUID in the clientId header sometime in Mid-March. This will completely break this module.

I have modified my copy to add the extra parameter. To accomplish this you must modify the following files. Public\CWSession.ps1

In the param section add a new parameter for ClientID. I added this between PrivateKey and OverrideSSL which ended in my lines 32-35 appearing thus:

    [string]$PrivateKey,
[Parameter(ParameterSetName='Normal', Position=3, Mandatory=$true)]
    [ValidateNotNullOrEmpty()]
    [string]$ClientID,

Then modify the sections in Begin to include the new ClientID variable, so that that section appears Thus: Begin { [CWApiRestSession] $cwSession = $null;

    if (!$OverrideSSL)
    {
        $cwSession = [CWApiRestSession]::New($Domain, $CompanyName, $PublicKey, $PrivateKey, $ClientID);
    }
    else 
    {
        $cwSession = [CWApiRestSession]::New($Domain, $CompanyName, $PublicKey, $PrivateKey, $ClientID, $true);
    }
}

Then in the Private\PSCWApiClasses.ps1 file Near line 154 I added a line to define the $clientID variable. So the lines immediately following the CWApiRestSession declaration on line 162 now look *thus. CWApiRestSession ([string] $domain, [string] $companyName, [string] $publicKey, [string] $privateKey, [string] $clientID) { $this.Domain = $domain; $this.CompanyName = $companyName; $this.PublicKey = $publicKey; $this.PrivateKey = $privateKey; $this.clientID = $clientID;

Then in the overload for including the overrideSSL function beginning around line 178 it it also included there. CWApiRestSession ([string] $domain, [string] $companyName, [string] $publicKey, [string] $privateKey, [string] $clientID, [bool] $overrideSSL) { $this.Domain = $domain; $this.CompanyName = $companyName; $this.PublicKey = $publicKey; $this.PrivateKey = $privateKey; $this.OverrideSSL = $overrideSSL; $this.ClientID = $clientID;

Then in the definition of the _buildHTTPHeader function, I added the header for clientId. So around line 211-213 it now looks like this:

hidden [void] _buildHttpHeader ()
{
    $this.Header = [hashtable] @{
        "Authorization"    = $this._createCWAuthenticationString();
        "Accept"           = "application/vnd.connectwise.com+json;";
        "Type"             = "application/json";
        "clientId"         = $this.clientID;
    }

    if ($this.OverrideSSL)
    {
        $this.Header.Add("x-cw-overridessl", "True");
    }
}

That's the end of the changes that I've made to date. It appears to be passing things correctly now, but I won't know for certain how well it works until they start requiring that clientId header.