
vRealize Automation (vRA) is a powerful tool for managing your IT resources efficiently. It's like having a digital assistant that helps you deploy and manage everything from virtual machines to applications with the click of a button. One way to make the most of vRA is to use its REST API, which allows you to automate your workflows and enjoy several benefits in the process.
Why Use the vRealize Automation REST API to Trigger Workflows?
- Automation and Integration
- Orchestration
- Efficiency and Consistency
- Self-Service Portals
How to Trigger vRealize Automation Workflows Using the REST API
Triggering vRA workflows using the REST API is simple and follows these steps:
1. Login
* First, log in to vRA to get an access token. This token is your "key" for making requests through the API.
The below Login code in JavaScript
//Get the Refresh Token
var loginObj = {};
loginObj.domain = domain;
loginObj.password = password;
loginObj.scope = ""
loginObj.username = user;
var loginJason = JSON.stringify(loginObj);
//login URL
var operationUrl = "/csp/gateway/am/api/login?access_token"
var request = restHost.createRequest("POST", operationUrl, loginJason);
request.setHeader("Content-Type", "application/json");
var response = request.execute();
System.log(response.contentAsString);
var res = JSON.parse(response.contentAsString);
//var token = res.cspAuthToken;
System.log("token: " + res['refresh_token']);
RefreshToken = res['refresh_token']
//Get Bearer Token
var restHost = rest_host
var loginObj1 = {};
loginObj1.refreshToken=RefreshToken;
var loginJason = JSON.stringify(loginObj1);
var operationUrl = "iaas/api/login"
var request = restHost.createRequest("POST", operationUrl, loginJason);
request.setHeader("Content-Type", "application/json");
var response = request.execute();
System.debug(response.contentAsString);
var res = JSON.parse(response.contentAsString);
System.log("token: " + response.contentAsString);
token = res.tokenType + ' ' + res.token
Below login Code In PowerShell
# Get the Refresh Token
$loginObj = @{
domain = $domain
password = $password
scope = ""
username = $UserName
}
$loginJson = $loginObj | ConvertTo-Json
$host_url = 'https://tenant.vRa_server_dns_name'
$operationUrl = $host_url + "/csp/gateway/am/api/login?access_token"
$request = Invoke-RestMethod -Method Post -Uri $operationUrl -Body $loginJson -Headers @{"Content-Type"="application/json"}
$refreshToken = ($request).refresh_token
Write-Host "Refresh Token: $refreshToken"
# Get Bearer Token
$loginObj1 = @{
refreshToken = $refreshToken
}
$loginJson = $loginObj1 | ConvertTo-Json
$operationUrl = $host_url + "/iaas/api/login"
$request = Invoke-RestMethod -Method Post -Uri $operationUrl -Body $loginJson -Headers @{"Content-Type"="application/json"}
$responseContent = $request.token
$token = $request.tokenType + ' ' + $request.token
Write-Host "Bearer Token: $token"
2. Get Workflow Details
* Obtain the vRealize Orchestrator (vRO) workflow ID by following these steps within the vRO user interface. In the provided example, the ID for the "TestingWorkflow" workflow is "978d6c1e-7fa8-4acf-9b2f-697c3291fe48"
3. Get the Execution ID from workflow
* Manually trigger the execution of a workflow and obtain the execution ID, please follow these steps, as illustrated in the screenshot below. In my example, the execution ID is “IDe73ed468-0607-4d1c-9e7c-7607a9ed367a”.
4. Run the REST API to get the Input Parameter format to workflow
Curl command to get the details.
curl -X 'GET' \
'https://tenant.vRa_DNS/vco/api/workflows/978d6c1e-7fa8-4acf-9b2f-697c3291fe48/executions/e73ed468-0607-4d1c-9e7c-7607a9ed367a?expand=string&showDetails=true' \
-H 'accept: application/json' \
-H 'Authorization: Bearer Token
The same code in PowerShell:
/# Define the URL
$url = "https://tenant.vRa_DNS/vco/api/workflows/978d6c1e-7fa8-4acf-9b2f-697c3291fe48/executions/e73ed468-0607-4d1c-9e7c-7607a9ed367a?expand=string&showDetails=true"
# Set the Bearer token
$token = ""
# Define headers
$headers = @{
"accept" = "application/json"
"Authorization" = "Bearer $token"
}
# Make the GET request
$response = Invoke-RestMethod -Uri $url -Method Get -Headers $headers
# Process the response as needed
# For example, you can access the response content using $response variable:
$response
Output Screen Shoot
5. Run the Workflow
* Send a "POST" request to the workflow. Provide the input it needs, and it will run. In the body just pest the input parameter details which came from last output.
curl -X 'POST' \
'https://tenant.vRa_DNS/vco/api/workflows/978d6c1e-7fa8-4acf-9b2f-697c3291fe48/executions' \
-H 'accept: application/json' \
-H 'Authorization: Bearer ' \
-H 'Content-Type: application/json' \
-d '{
"executionId": "IDe73ed468-0607-4d1c-9e7c-7607a9ed367a",
"parameters": [
{
"name": "var_0",
"type": "string",
"updated": true,
"value": {"string": {
"value": "ef3f4jhgyu786896623e"
}}
}
],
"profilerOptions": {
"debuggerEnabled": true,
"enabled": true,
"tokenReplayEnabled": true
}
}'
Same code In PowerShell:
# Define the URL
$url = "https://tenant.vRa_DNS/vco/api/workflows/978d6c1e-7fa8-4acf-9b2f-697c3291fe48/executions"
# Set the Bearer token
$token = ""
# Define headers
$headers = @{
"accept" = "application/json"
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
# Define the request body
$body = @{
"executionId" = "IDe73ed468-0607-4d1c-9e7c-7607a9ed367a"
"parameters" = @(
@{
"name" = "var_0"
"type" = "string"
"updated" = $true
"value" = @{
"string" = @{
"value" = "ef3f4jhgyu786896623e"
}
}
}
)
"profilerOptions" = @{
"debuggerEnabled" = $true
"enabled" = $true
"tokenReplayEnabled" = $true
}
} | ConvertTo-Json
# Make the POST request
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body
# Process the response as needed
# For example, you can access the response content using $response variable:
$response
6. Check Workflow Status
* Keep an eye on the workflow's status by checking with the server. You'll know when it's done.
The vRealize automation REST API is your secret weapon for making IT tasks easier. It automates tasks, connects processes, and keeps resources under control. As more companies turn to cloud and hybrid cloud solutions, vRA and its REST API will be your best friends for managing resources and services dynamically.