Get-PresenceType.ps1

<#
.Synopsis
   The function returns list of presence types
.DESCRIPTION
   The function returns a list of all presence types that are defined in the attendance system.
.PARAMETER URL
    Server API url.
.PARAMETER Token
    Authentication token for accessing API data. If you use the token for authentication, don't enter access key.
.PARAMETER AccessKey
    The AccessKey to get an authentication token for accessing API data. If you use the access key to get authentication token, don't enter token.
.EXAMPLE
   Get-PresenceType -URL https://intranet.company.com/webtime12/api -AccessKey 56879065
   This command retrieves the list of presence types with authentication via Accesskey
.EXAMPLE
   Get-PresenceType -URL https://intranet.company.com/webtime12/api -Token $MyToken
   This command retrieves the list of presence types with authentication via Token
#>

function Get-PresenceType {
    [CmdletBinding(DefaultParameterSetName='AccessKey')]
    param(
        # Server API url
        [Parameter(Mandatory = $true)]
        [string]$URL,
        # Authentication token for accessing API data
        [Parameter(Mandatory = $true,ParameterSetName='Token')]
        [string]$Token,
        # The AccessKey to get an authentication token for accessing API data
        [Parameter(Mandatory = $true,ParameterSetName='AccessKey')]
        [string]$AccessKey
    )

    Process {

        if ($PSCmdlet.ParameterSetName -eq 'AccessKey') {
            $SchemeToken = Get-Token -URL $URL -AccessKey $AccessKey
            $Token = $SchemeToken.Scheme + " " + $SchemeToken.Token
            }

       $url = $url + "/CodeLists/PresenceTypes"

       $Body = @{}

       $json = $body | ConvertTo-Json
       Write-Verbose -Message "Send request to API endpoint $URL with access key $Token."
       $PresType = Invoke-RestMethod -Method Post -Uri $url -Headers @{ Authorization = $Token } -Body $json -ContentType 'application/json'

       Write-Verbose -Message "Return object Presence Type."
       Write-Output $PresType
    }
}