Public/Subscriptions/Get-UKGEmployeeSubscription.ps1
|
function Get-UKGEmployeeSubscription { <# .SYNOPSIS Gets employee subscriptions from the UKG HR Service Delivery API. .DESCRIPTION Retrieves employee subscription information by ID or lists all subscriptions. .PARAMETER Id The unique identifier of the subscription to retrieve. .PARAMETER EmployeeId Filter subscriptions by employee ID. .PARAMETER All Retrieves all employee subscriptions. .PARAMETER PerPage Number of results per page (1-100, default 25). .PARAMETER Cursor Pagination cursor for retrieving a specific page. .EXAMPLE Get-UKGEmployeeSubscription -Id "sub123" .EXAMPLE Get-UKGEmployeeSubscription -EmployeeId "emp123" .EXAMPLE Get-UKGEmployeeSubscription -All .OUTPUTS UKG.EmployeeSubscription or array of UKG.EmployeeSubscription objects. #> [CmdletBinding(DefaultParameterSetName = 'ById')] [OutputType([PSCustomObject])] param( [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)] [ValidateNotNullOrEmpty()] [Alias('SubscriptionId')] [string]$Id, [Parameter(ParameterSetName = 'ByEmployee')] [Parameter(ParameterSetName = 'List')] [string]$EmployeeId, [Parameter(ParameterSetName = 'List')] [switch]$All, [Parameter(ParameterSetName = 'ByEmployee')] [Parameter(ParameterSetName = 'List')] [ValidateRange(1, 100)] [int]$PerPage = 25, [Parameter(ParameterSetName = 'ByEmployee')] [Parameter(ParameterSetName = 'List')] [string]$Cursor ) process { $queryParams = @{} switch ($PSCmdlet.ParameterSetName) { 'ById' { $response = Invoke-UKGRequest -Endpoint "/employee_subscriptions/$Id" -Method GET if ($response) { $response.PSObject.TypeNames.Insert(0, 'UKG.EmployeeSubscription') } return $response } 'ByEmployee' { $queryParams['per_page'] = $PerPage if ($Cursor) { $queryParams['cursor'] = $Cursor } if ($EmployeeId) { $queryParams['employee_id'] = $EmployeeId } $response = Invoke-UKGRequest -Endpoint '/employee_subscriptions' -Method GET -QueryParameters $queryParams -ReturnHeaders if ($response.Data) { foreach ($sub in $response.Data) { $sub.PSObject.TypeNames.Insert(0, 'UKG.EmployeeSubscription') } $pagination = Get-UKGNextPage -Headers $response.Headers if ($pagination.NextCursor) { Write-Verbose "Next cursor: $($pagination.NextCursor)" } return $response.Data } } 'List' { $queryParams['per_page'] = $PerPage if ($Cursor) { $queryParams['cursor'] = $Cursor } if ($EmployeeId) { $queryParams['employee_id'] = $EmployeeId } if ($All -and -not $Cursor) { $allSubs = Get-UKGAllPages -Endpoint '/employee_subscriptions' -Method GET -QueryParameters $queryParams foreach ($sub in $allSubs) { $sub.PSObject.TypeNames.Insert(0, 'UKG.EmployeeSubscription') } return $allSubs } else { $response = Invoke-UKGRequest -Endpoint '/employee_subscriptions' -Method GET -QueryParameters $queryParams -ReturnHeaders if ($response.Data) { foreach ($sub in $response.Data) { $sub.PSObject.TypeNames.Insert(0, 'UKG.EmployeeSubscription') } return $response.Data } } } } } } |