Posted in : Citrix, Powershell Av Stina Perbo Utas Översätt med Google ⟶

4 years ago

While working with the Citrix Cloud monitor service is amazing, it is also quite unpredictable and we often experience bugs without any notice.

The latest one is related to paging, where the nextLink is presented as http instead of https, which breaks recursive searches. Now this is not the hardest one to fix, but the message can throw you off a bit.

The error states ”Authroization or Customer header is unavailable.” (before you ask, yes the error message is misspelled). And when built into a recursive function It’s not the easiest to spot.

Invoke-WebRequest : Access denied to query Monitor objects : Authorization or Customer header is unavailable.
At line:1 char:1
+ Invoke-WebRequest -Uri 'http://{customerId} ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

The solution is simple, just replace http:// with https:// and everything will start working again.

Full recursive function

Function Invoke-WebRequestRecursive {
    $Ret = Invoke-WebRequest -Uri $uri -Headers $headers -UseBasicParsing -ErrorAction Stop
    [array]$Value = @()
    $Value += (($Ret).Content | ConvertFrom-Json).Value
    If(($ret.Content | ConvertFrom-Json)."@odata.nextLink"){
        $nUri = ($ret.Content | ConvertFrom-Json)."@odata.nextLink".Replace('http://','https://')
        $Value += Invoke-WebRequestRecursive -uri $nUri -headers $headers
    Return $Value

Hopefully this save someone a headache or two!

I’ve submitted this as an issue in citrix github so hopefullt this will be resolved soon.


Citrix Developer API

Tags : API, Citrix, Citrix Monitor API, Microsoft, OData API, PowerShell

Personlig rådgivning

Vi erbjuder personlig rådgivning med författaren för 1400 SEK per timme. Anmäl ditt intresse i här så återkommer vi så snart vi kan.

Add comment

Your comment will be revised by the site if needed.