# Automating Automation (Updated)
**Using vRO REST API. - (Updated for vRA 8.4)**
---
I recently had a use case where I wanted to execute a vRealize Orchestrator Workflow by using REST API. There is some documentation available but not a lot of details on how to get and use variables, sdk-objects and bearer token for permission. Here is how I made the vRO REST API calls with PowerShell using vRealize Orchestrator built-into vRA.
---
Steps:
1. Permission:
* Need to get a Bearer Token from vRO to make REST API Call to execute Workflow.
* To get a Bearer Token you need to make an REST API Call with username/password. See example code.
2. Workflow Information:
* Get Workflow ID.
* Get Workflow variable inputs.
* Get sdk-object names from a successful Workflow run.
* See Screen Shots and sample code.
3. Run the Workflow you want to use REST API with manually at least one time successfully. When you look at the variables of a successful Workflow run it shows you what the Workflow is expecting for variables and sdk-objects. See Screen Shots.
---
###### Code to get bearer Token (PowerShell):
You can't use vRO REST API without getting bearer token first.
###### (Note: When vRealize Automation 8.4 was released there was a small change to api to get Bearer Token. See the changes in the code area. Everything else has stayed the same for my processes.)
{{< highlight powershell >}}
# Get Bearer Token from vRA REST API Call
# Some of the commented lines are in the code for testing. I use to check variable
# values when building the Automation.
# I am showing password in this example. In Production I get the Password from a Hashi
# Secret Server and DO NOT have the password Hard Coded.
# --- [ Variables ] ---
$password = 'VMware1'
# --- [ Headers ] ---
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "application/json")
# --- [ Body ] ---
$body = "{
`n `"password`": `"passwordString`",
`n `"username`": `"administrator`"
`n}"
$body = $body -Replace("passwordString",$password)
#$body
# --- [ Invoke REST API ] ---
# vRA 8.3 Use next line
$response = Invoke-RestMethod -SkipCertificateCheck 'https://vRA-FQDN.domain.name/csp/gateway/am/api/login?access_token' -Method 'POST' -Headers $headers -Body $body
# vRA 8.4 Use next line
$response = Invoke-RestMethod -SkipCertificateCheck 'https://vRA-FQDN.domain.name/csp/gateway/am/api/login?cspAuthToken' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
#$response
# vRA 8.3 Use next line
#$response.access_token
# vRA 8.4 Use next line
#$response.cspAuthToken
# vRA 8.3 Use next line
$bearer_token = "Bearer " + $response.access_token
# vRA 8.4 Use next line
$bearer_token = "Bearer " + $response.cspAuthToken
# $bearer_token
{{< /highlight >}}
###### Code to get execute a vRO Workflow using API Call (PowerShell):
{{< highlight powershell >}}
# Run vRA Workflow using API Call
# --- [ Variables ] ---
$vmName = 'DBH-1234'
$emailAddress = Dale.Hassinger@vCROCS.info'
$OSVersion = 'Ubuntu18044'
$PSText = 'G:\Scripts\Create-Linux-Server-Step-1-v01-PROD.ps1 -vmNAME $vmName -emailAddress $emailAddress -OSVersion $OSVersion'
# --- [ Headers ] ---
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/xml")
$headers.Add("Authorization", $bearer_token)
# --- [ Body ] ---
$body = '