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() $pageCount = 0 do { try { $result = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers } catch { throw "Failed to retrieve SuccessFactors resource '$Resource' from '$uri': $($_.Exception.Message)" } $pageCount++ foreach ($row in @($result.d.results)) { $rows.Add($row) } $uri = [string]$result.d.__Next } while (-not [string]::IsNullOrWhiteSpace($uri)) if ($rows.Count -eq 0) { Send-ConnectorLog -Text "SuccessFactors returned no $Resource rows; check the API user's permissions and the query" -Type Warning | Out-Null } else { Send-ConnectorLog -Text "Fetched $($rows.Count) $Resource row(s) in $pageCount page(s)" | Out-Null } return $rows } |