I am trying to test out the VCSA 6.5 Backup script with vRO available out there. Tested working using Curl, PowerShell, PowerShell using Invoke-RestMethod but can't get it to fully work in vRo. The problem I am having is authenticating using the session ID.
Part 1 - Obtain session ID using SSO Credentials:
Wth Curl: (Works)
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'vmware-use-header-authn: test' --header 'vmware-api-session-id: null' -u 'administrator@vsphere.local' -p 'Passw0rd!' 'https://10.158.47.99/rest/com/vmware/cis/session' --insecure
With PowerShell: (Works)
$Server = '10.158.47.99'
$Url = "https://${server}/rest/com/vmware/cis/session"
$secpasswd = ConvertTo-SecureString "Passw0rd!" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("administrator@vsphere.local", $secpasswd)
#Invoke-RestMethod -Method POST -Uri $Url -Header @{ "X-ApiKey" = $apiKey }
$resp = Invoke-RestMethod -Method POST -Uri $Url -Credential $creds
$sessionID = $resp.Value
Write-Host "Session Requested -- $sessionID"
With VRO: (Works)
var requestType = "POST";
var operationUrl = "https://10.158.47.99/rest/com/vmware/cis/session"
var req = restHost.createRequest(requestType, operationUrl, "");
var resp;
resp = req.executeWithCredentials(ssoUser, ssoPassword);
var sessionid = JSON.parse(resp.contentAsString).value;
System.log("New Session id is : " + sessionid);
Part 2 - Use Obtained sessionID to call https://vc/rest/appliance/recovery/backup/parts and get "backup parts information"
With Curl: (Works)
curl -sik -H 'Accept:application/json' -H "vmware-api-session-id:2b26afc12cd4b374d998e2d63b3b9573" -X GET https://10.158.47.99/rest/appliance/recovery/backup/parts
With PowerShell: (Works)
$headers = @{}
$headers.Add("Accept","application/json")
$headers.Add("vmware-api-session-id", $sessionID)
#$headers.Add("Authorization", "Basic $sessionID")
$Url = "https://${server}/rest/appliance/recovery/backup/parts"
$PartResponse = Invoke-RestMethod -Method GET -Headers $headers -Uri $Url
$PartResponse.value
With VRO: (Not Working)
var request = restHost.createRequest("GET", "https://10.158.47.99/rest/appliance/recovery/backup/parts", "");
request.setHeader("Accept", "application/json");
request.setHeader("vmware-api-session-id", sessionid);
System.log("fullurl -- " + request.fullUrl);
System.log("content-type -- " +request.contentType);
System.log("getMethod -- " +request.getMethod());
var resp2 = request.execute();
System.log("get parts list response code: " + resp2.statusCode);
System.log("get parts list response body: " + resp2.contentAsString);
VRO Log::
[2017-09-13 16:55:47.711] [I] New Session id is : aab84e24f33916b86b90a7bae6991360
[2017-09-13 16:55:47.713] [I] fullurl -- https://10.158.47.99/rest/appliance/recovery/backup/parts
[2017-09-13 16:55:47.714] [I] content-type -- null
[2017-09-13 16:55:47.715] [I] getMethod -- GET
[2017-09-13 16:55:47.908] [I] get parts list response code: 403
[2017-09-13 16:55:47.909] [I] get parts list response body: {"type":"com.vmware.vapi.std.errors.unauthorized","value":{"messages":[{"args":[],"default_message":"Unable to authorize user","id":"vapi.security.authorization.invalid"}]}}
Code I am testing - contains code for backup part list but does not work: http://vmwarebits.com/vcenterbackup
Original Source Code - works but no backup part list: how to authenticate for rest api with vCenter 6.5 appliance
Anyone know what I am doing wrong???
The VRO code seems to be a directly translation of the Curl and PowerShell Script......