Public/ps1/Job/Get-LeftConnectResult.ps1
function Get-LeftConnectResult{ [CmdletBinding()] param($request, $body) $token = Get-LeftConnectToken $headers = @{"Authorization"="Bearer "+$token;} $requestUrl = (Get-LeftConnectUrlHost) + $request Log("Requesting url: $requestUrl") try { if ($body) { $answer = Invoke-RestMethod $requestUrl -Method Post -Body $body -ContentType "application/json; charset=utf-8" -Headers $headers } else { $answer = Invoke-RestMethod $requestUrl -Headers $headers } } catch { write-host "Token not accepected. Try renewing" if ($global:token) { Remove-Variable token -Scope Global } $token = Get-LeftConnectToken -force $true $headers = @{"Authorization"="Bearer "+$token;} if ($body) { $answer = Invoke-RestMethod $requestUrl -Method Post -Body $body -ContentType "application/json; charset=utf-8" -Headers $headers } else { $answer = Invoke-RestMethod $requestUrl -Headers $headers } } return $answer } |