Howto: Get a refresh token from Aria Automation using the REST API in an Orchestrator action script
search cancel

Howto: Get a refresh token from Aria Automation using the REST API in an Orchestrator action script

book

Article ID: 413395

calendar_today

Updated On:

Products

VCF Operations/Automation (formerly VMware Aria Suite)

Issue/Introduction

  • Guidance on how to get a refresh token for authentication in Automation, by creating an Action in Orchestrator

Environment

  • VMware Aria Automation
  • VMware Aria Orchestrator

Resolution

Please note that there are multiple ways to interact with an Aria Automation host from Orchestrator, including:

  • Using the VRA / Aria Automation plugin for Orchestrator
    1. Use the Add vRA Host workflow to add your Automation system to the inventory
    2. Use the Get operation, Post operation etc workflows to make REST calls as the current user
  • It is also possible to add it as a generic HTTP-REST host, although these workflows are less integrated

 

Action Script

The following sample Javascript code can be used to acquire refresh token in an Orchestrator Action.
This is intended as an illustrative minimal example and does not include any error handling.

var vraHost = "https://<VRA-FQDN>"
// The Automation username can be given without specifying domain in most setups:
var username = "########"
var password = "########"
var creds = '{"username": "' + username + '", "password": "' + password + '"}'

endpoint = vraHost + "/csp/gateway/am/api/login?access_token"
vraRESThost = RESTHostManager.createHost("dynamicRequest")
var vRA = RESTHostManager.createTransientHostFrom(vraRESThost)

vRA.url = vraHost

request = vRA.createRequest("POST", endpoint, creds)
request.setHeader("Content-Type", "application/json")

var response = request.execute()
var result = response.contentAsString

// This result can be parsed as JSON to pull out the refresh token and obtain a bearer token:
System.log(result)

// Close the connection once it is no longer needed
request.setHeader("Connection", "close");