Skip to content

Using a template to create Get CWMTicketTask

Chris Taylor edited this page Apr 16, 2021 · 1 revision

We will start by pulling up the Get-CWMTemplate and, opening up the API documentation for the endpoint we are working with.

We create a new file Get-CWMTicketTask.ps1 in the appropriate directory and, update the function name to match.

We then want to update the to match the endpoint we are using.

Add a parameter for parentId and make it mandatory.

function Get-CWMTicketTask {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [int]$parentId,
        [int]$id,
        [string]$Condition,
        [ValidatePattern('\S* (desc|asc)')]
        [string]$orderBy,
        [string]$childConditions,
        [string]$customFieldConditions,
        [int]$page,
        [int]$pageSize,
        [string[]]$fields,
        [switch]$all
    )

    $Endpoint = "/service/tickets/$($parentId)/tasks"
    if($id){ $Endpoint = Join-Url $Endpoint $id }

    return Invoke-CWMGetMaster -Arguments $PsBoundParameters -Endpoint $Endpoint
}

All done, it is that easy to add a new GET endpoint.