Resources/Regions.ps1
function Get-ITGlueRegions { [CmdletBinding(DefaultParameterSetName = 'index')] Param ( [Parameter(ParameterSetName = 'index')] [Parameter(ParameterSetName = 'show')] [Nullable[Int64]]$country_id = $null, [Parameter(ParameterSetName = 'index')] [String]$filter_name = '', [Parameter(ParameterSetName = 'index')] [String]$filter_iso = '', [Parameter(ParameterSetName = 'index')] [Nullable[Int]]$filter_country_id = '', [Parameter(ParameterSetName = 'index')] [ValidateSet( 'name', 'id', 'created_at', 'updated_at', ` '-name', '-id', '-created_at', '-updated_at')] [String]$sort = '', [Parameter(ParameterSetName = 'index')] [Nullable[Int64]]$page_number = $null, [Parameter(ParameterSetName = 'index')] [Nullable[int]]$page_size = $null, [Parameter(ParameterSetName = 'show')] [Nullable[Int64]]$id = $null ) $resource_uri = ('/regions/{0}' -f $id) if ($country_id) { $resource_uri = ('/countries/{0}/relationships' -f $country_id) + $resource_uri } if ($PSCmdlet.ParameterSetName -eq 'index') { if ($filter_name) { $body += @{'filter[name]' = $filter_name} } if ($filter_iso) { $body += @{'filter[iso]' = $filter_iso} } if ($filter_country_id) { $body += @{'filter[country_id]' = $filter_country_id} } if ($sort) { $body += @{'sort' = $sort} } if ($page_number) { $body += @{'page[number]' = $page_number} } if ($page_size) { $body += @{'page[size]' = $page_size} } } try { $ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password) $rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers ` -body $body -ErrorAction Stop -ErrorVariable $web_error } catch { Write-Error $_ } finally { [void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist } $data = @{} $data = $rest_output return $data } |