christaylorcodes / ConnectWiseManageAPI

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

Update-CWMScheduleEntry missing - trying to fix. #35

Closed Absoblogginlutely closed 2 years ago

Absoblogginlutely commented 2 years ago

I noticed there was no Update-CWMScheduleEntry function and wanted to create one so that I can update my tentative schedules that were created in Outlook and synchronized over to Connectwise to Firm. I copied the updatetemplate file over to the schedule folder, updated the endpoint and then tried to update a schedule entry with the following results

8:01:53: C:\Temp\ConnectWiseManageAPI-master\ConnectWiseManageAPI-master>  Update-CWMScheduleEntry -id 935317 -operation replace -path 'status/id' -value 2

Write-Error: C:\Temp\ConnectWiseManageAPI-master\ConnectWiseManageAPI-Master\ConnectWiseManageAPI\Private\Invoke\Invoke-CWMUpdateMaster.ps1:27

Line |
  27 |  …        $Result = Invoke-CWMWebRequest -Arguments $WebRequestArguments
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | An exception has been thrown. --> Response status code does not indicate success: 403 (Forbidden). at
     | Invoke-CWMWebRequest,
     | C:\Temp\ConnectWiseManageAPI-master\ConnectWiseManageAPI-master\ConnectWiseManageAPI\Private\Invoke\Invoke-CWMWebRequest.ps1: line 42 at Invoke-CWMUpdateMaster, C:\Temp\ConnectWiseManageAPI-master\ConnectWiseManageAPI-master\ConnectWiseManageAPI\Private\Invoke\Invoke-CWMUpdateMaster.ps1: line 27 at Update-CWMScheduleEntry, C:\Temp\ConnectWiseManageAPI-master\ConnectWiseManageAPI-master\ConnectWiseManageAPI\Public\Schedule\ScheduleEntries\Update-CWMScheduleEntry.ps1: line 17 at <ScriptBlock>, <No file>: line 1

Any ideas why this wouldn't work - is this why there is no built in update-CWMSchedule entry (lol) ?

Also, for reference the wiki on the update template at https://github.com/christaylorcodes/ConnectWiseManageAPI/wiki/Using-a-template-to-create-Update-CWMContact uses Invoke-CWMPatchMaster -Arguments $PsBoundParameters -Endpoint $Endpoint whereas I think it should now be Invoke-CWMUpdateMaster -Arguments $PsBoundParameters -Endpoint $Endpoint

My update-CWMScheduleEntry.ps1 file looks like the following:-

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'Used by sub-function')]
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    param(
        [Parameter(Mandatory = $true)]
        [int]$id,
        [Parameter(Mandatory = $true)]
        [validateset('add', 'replace', 'remove')]
        [string]$Operation,
        [Parameter(Mandatory = $true)]
        [string]$Path,
        [Parameter(Mandatory = $true)]
        $Value
    )

    $Endpoint = '/schedule/entries/$($id)'
    Invoke-CWMUpdateMaster -Arguments $PsBoundParameters -Endpoint $Endpoint
}
christaylorcodes commented 2 years ago

Reference