Private/Invoke-SFRestMethod.ps1
|
<# .SYNOPSIS Retrieves a SuccessFactors OData v2 resource and follows all pagination links. #> function Invoke-SFRestMethod { [CmdletBinding()] [OutputType([System.Collections.Generic.List[object]])] param ( [Parameter(Mandatory)] [string]$BaseUrl, [Parameter(Mandatory)] [string]$Resource, [string]$QueryString = '' ) $headers = Get-SFHeader $uri = $BaseUrl.TrimEnd('/') + '/odata/v2/' + $Resource + $QueryString $rows = [System.Collections.Generic.List[object]]::new() do { try { $result = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers } catch { throw "Failed to retrieve SuccessFactors resource '$Resource' from '$uri': $($_.Exception.Message)" } foreach ($row in @($result.d.results)) { $rows.Add($row) } $uri = [string]$result.d.__Next } while (-not [string]::IsNullOrWhiteSpace($uri)) return $rows } |