CallRestEndPoint.ps1
function CallRestEndPoint { <# .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 function1 '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" } return $result } end { } } |