Skip to content

Using a template to create New CWMTicketTask

Chris Taylor edited this page Apr 15, 2021 · 8 revisions

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

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

Update the function with the version of the API you are using. It can be found at the top of the docs.

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

New endpoints are the most complicated as you need to handle ALL the parameters listed in the schema.

You will want to type all your inputs appropriately

  • integer - [int]
  • string - [string]
  • boolean - [boolean]
  • any 'reference' - [hashtable]
  • enum - create a validation set

In this case, the parentId in the URL is the same as the ticketId in the body so we will use the body variable to set the URL parameter as well. This allows us to have one parameter instead of two and so we don't have to 'skip' the parentId parameter when creating the body. We can add parentId as an alias to help with discovery.

We don't have any parameters we need to skip so we can remove that.

function New-CWMTicketTask {
    # 2020.4
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '', Justification = 'Used by sub-function')]
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
    param(
        [int]$id,
        [Alias('parentId')]
        [int]$ticketId,
        [string]$notes,
        [boolean]$closedFlag,
        [int]$priority,
        [hastable]$schedule,
        [hashtable]$code,
        [string]$resolution,
        [ValidateSet('Transfer', 'Delete', 'Done')]
        $childScheduleAction,
        [int]$childTicketId,
        [hashtable]$_info
    )

    $URI = "https://$($script:CWMServerConnection.Server)/v4_6_release/apis/3.0/service/tickets/$($ticketId)/tasks"

    return Invoke-CWMNewMaster -Arguments $PsBoundParameters -URI $URI
}