User Tools

Site Tools


vrealize:restapi:start

Rest API

Get cafeclient ID from vRA:

Look in: /etc/vcac/solution-users.properties
cafe_cli=cafe_cli-xxxxxx

Get token for vRO:

function LogontovRO()
{
   $url = "https://<FQDN_of_vRO>/SAAS/t/vsphere.local/auth/oauthtoken?grant_type=password"
 
 
 
   $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
   $headers.Add('Content-Type','application/x-www-form-urlencoded')
   $data = "username=auser&password=apassword&client_id=cafe_cli-xxxxxxx&domain=AnAdDomain";
 
   $response = Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body $data -SessionVariable 'vROSession'
   if ($response.StatusCode -ne 200)
   {
        Write-Host "unable to login"
        return $null;
   }
   $jsondata = $response.Content | ConvertFrom-Json
   Write-Host $jsondata
   return $jsondata.access_token;
}

Get token for vRA:

function LogonTovRA()
{
   $url = "https://<FQDNOFVRA>/identity/api/tokens"
   $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
   $headers.Add('Accept','application/json')
   $headers.Add('Content-Type','application/json')
 
   $data = @{
    username="auser@domain.local"
    password="APassword"
    tenant="vsphere.local"
}
 
    $data = $data | ConvertTo-Json
   $response = Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body $data -SessionVariable 'vRASession'
   if ($response.StatusCode -ne 200)
   {
        Write-Host "unable to login"
        return $null;
   }
   $jsondata = $response.Content | ConvertFrom-Json
   #Write-Host $jsondata.id
   return $jsondata.id;
}
vrealize/restapi/start.txt ยท Last modified: 2021/04/07 23:35 by vmware