CallRestUri.ps1
function CallRestUri { <# .SYNOPSIS This function ... .DESCRIPTION A bit more description .PARAMETER FromPipeline Shows how to process input from the pipeline, remaining parameters or by named parameter. .EXAMPLE CallRestUri 'abc' Description of the example. #> <# Enable -Confirm and -WhatIf. #> [CmdletBinding(SupportsShouldProcess = $true)] param( $method, $path, $extraParams ) begin { } process { Write-Verbose "Raw output: $rawOutput" If( $Script:prefix -eq $null ) { Connect-Qlik > $null } If( ! $path.StartsWith( "http" ) ) { $path = $Script:prefix + $path } $xrfKey = GetXrfKey If( $path.contains("?") ) { $path += "&xrfkey=$xrfKey" } else { $path += "?xrfkey=$xrfKey" } $params = DeepCopy $api_params If( $extraParams ) { $params += $extraParams } If( !$params.Header ) { $params.Header = @{} } If( !$params.Header.ContainsKey("x-Qlik-Xrfkey") ) { Write-Verbose "Adding header x-Qlik-Xrfkey: $xrfKey" $params.Header.Add("x-Qlik-Xrfkey", $xrfKey) } If( $params.Body ) { Write-Verbose $params.Body } Write-Verbose "Calling $method for $path" If( $script:webSession -eq $null ) { $result = Invoke-RestMethod -Method $method -Uri $path @params -SessionVariable webSession $script:webSession = $webSession } else { $result = Invoke-RestMethod -Method $method -Uri $path @params -WebSession $script:webSession } if( !$rawOutput ) { Write-Verbose "Formatting response" $result = FormatOutput($result) } return $result } end { } } |