Public/Invoke-SFRestMethod.ps1
|
<# .SYNOPSIS Sends GET requests to the SuccessFactors OData v2 API and handles pagination. .DESCRIPTION Invokes REST API calls against the SuccessFactors OData v2 endpoint for the specified resource. Automatically handles pagination by following the __Next link in responses. .PARAMETER BaseUrl The base URL of the SuccessFactors API instance (e.g., https://api.successfactors.com). .PARAMETER Resource The OData resource name to retrieve (e.g., User, EmpEmployment). .PARAMETER QueryString Optional OData query parameters (e.g., '?$expand=address'). .OUTPUTS System.Array - Array of resource objects from SuccessFactors. .NOTES Requires an active connection established by Connect-SF. Automatically handles pagination for large result sets. #> function Invoke-SFRestMethod { param( [Parameter(Mandatory = $true)] [string] $BaseUrl, [Parameter(Mandatory = $true)] [string] $Resource, [Parameter(Mandatory = $false)] [string] $QueryString = '' ) $headers = Get-SFHeader $uri = $BaseUrl + '/odata/v2/' + $Resource + $QueryString try { $result = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers } catch { throw "Failed to retrieve SuccessFactors resource '$Resource' from '$uri': $_" } $rows = $result.d.results while ($result.d.__Next) { try { $result = Invoke-RestMethod -Method Get -Uri $result.d.__Next -Headers $headers } catch { throw "Failed to retrieve next page for resource '$Resource': $_" } $rows += $result.d.results } return $rows } |