Has anyone setup using REST APIs for on-prem CVAD ...
# citrix-vad
m
Has anyone setup using REST APIs for on-prem CVAD post 2203 with the Web Studio update? I am on 2402 and was testing to see if I could use them but keep getting a 401 Unauthorized even though I am an admin in the farm.
s
401 means you're not properly authenticated. Did you generate the bearer token first?
m
Yes per the online doc, I have tried user:pass as well as powershell get-credential to then:
Copy code
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($adminCredentical)
$EncodedAdminCredentical = [Convert]::ToBase64String($Bytes)
s
how does look your Invoke-RestMethod to get the bearer token if I may?
m
Copy code
$requestUri = "https://<server>/cvad/manage/me"
$headers = @{
    "Accept" = "application/json";
    "Authorization" = "CWSAuth Bearer=$EncodedAdminCredentical";
    "Citrix-CustomerId" = "CitrixOnPremises";
}
Invoke-RestMethod -Uri $requestUri -Method GET -Headers $headers
s
You're missing a step I think. Bearer token is not $EncodedAdminCredentical. It's the response from another API Call: $requestTokenUri = "https://<server>/cvad/manage/Tokens" $headers = @{ "Accept" = "application/json"; "Authorization" = "Basic $EncodedAdminCredentical"; } $response = Invoke-RestMethod -Uri $requestTokenUri -Method POST -Headers $headers Write-host ($response | ConvertFrom-Json)
Console output should display an object with a property "Token" with something starting by ey.....
This is the bearer token to use in your powershell script.
Also, remove ";" from your headers
m
cool I will give that a shot, thanks!
And it worked btw 🙂
👍 1
s
The token expires after an hour if I remember so, redo the token request on a regular basis ;)
👍 1