Calling VCF Automation from a workflow
Recipes 8.5 and 8.6 had VCF Automation call Orchestrator. Often you need the other direction as well: a workflow that looks up a deployment, reads a project, or checks a catalog item before it does its own work. You could register VCF Automation as a plain REST host (recipe 5.2) and handle the login yourself. You don’t have to. The embedded Orchestrator comes with a plug-in for VCF Automation and a host that is already set up, and the plug-in deals with the tokens.
Getting ready
- The embedded Orchestrator of a VM Apps organization, as in the rest of this chapter.
- The action module
com.vcfguide.chapter8.
How to do it
Find the host that’s already there
- Go to Administration > Inventory and expand VCF Automation for VM Apps. It holds one host, Default, followed by the address of the VCF Automation that the Orchestrator is embedded in.

In scripts, that host is an object of type VRA:Host. VraHostManager.findHostsByType("vra-onprem") returns it, and you can pick it as the value of a workflow input or variable of that type.
Write one action for every GET
- Create the action
vcfaGetincom.vcfguide.chapter8, with the inputshost(VRA:Host) andpath(string), and the return typestring:
// GET one VCF Automation API path through the plug-in host. Reads only.if (!host) { throw "vcfaGet: the input host is required";}if (!path || path.charAt(0) !== "/") { throw "vcfaGet: path must start with /, got: " + path;}var client = host.createRestClient();var request = client.createRequest("GET", path, null);var response = client.execute(request);System.debug("GET " + path + " returned " + response.statusCode);if (response.statusCode !== 200) { throw "vcfaGet: GET " + path + " on " + host.name + " failed with HTTP " + response.statusCode + ": " + response.contentAsString;}return response.contentAsString;createRestClient() gives you a client that already knows the address and signs every request for you. There’s no login call and no token in your code.
Call it
- In a scriptable task, or in a test action, read the deployments you can see:
var host = VraHostManager.findHostsByType("vra-onprem")[0];var body = JSON.parse(System.getModule("com.vcfguide.chapter8") .vcfaGet(host, "/deployment/api/deployments?size=20"));System.log(body.totalElements + " deployments");for (var i = 0; i < body.content.length; i++) { System.log(body.content[i].name);}- Now ask for something your account isn’t allowed to see. Run the same code as a user who isn’t a VCF Automation administrator, with the path
/iaas/api/projects. The action fails withHTTP 403and a body that saysforbidden. The next section explains why.
How it works
Per-user sessions. The Default host uses Per User Session: each call is made as the user running the workflow, with that user’s rights in VCF Automation. In the 9.1.1 lab, a service account that could list deployments (200, an empty list) got 403 on /iaas/api/projects and on /catalog/api/items, both from the same script. That’s what you want for workflows people run themselves: nobody gets more than they already have. It’s also the first thing to check when a workflow works for you and fails for a colleague.
Be careful when VCF Automation starts the workflow, from a catalog item (recipe 8.6) or a subscription (recipe 8.5). Find out which account those runs use before you count on its rights. If that account can’t read what the workflow asks for, every run fails with 403, and a host of your own (There’s more) is the fix.
Status codes are numbers. response.statusCode compares with !== like any other number, and contentAsString is the raw body. Parse it with JSON.parse once, and pass the object around, not the string.
VM Apps and All Apps. The inventory has two VCF Automation plug-ins. VCF Automation for VM Apps (VRA:Host) talks to the APIs this book uses: deployments, catalog, IaaS, projects. VCF Automation for All Apps (VCFA:Host) talks to an All Apps organization, whose API is Kubernetes-style. Its Add a VCF Automation Host workflow asks for an API token and a k8sApiVersion instead of a user name. In the lab it had no hosts. Remember that many All Apps projects need an external Orchestrator, not the embedded one.
There's more
A host of your own, for service work. When a workflow must do the same thing whoever runs it, for example read every project to build a report, add a second host with a service account. Run the library workflow Add vRA Host. Its inputs are name, vraHost (the URL), tenant, connectionType (vra-onprem), sessionMode (Shared Session for a service account), loginType, user and password or a token, and ignoreWarnings for the certificate prompt. It returns the new VRA:Host, which you pass to vcfaGet instead of Default. Update a VCF Automation Host and Delete a VCF Automation Host are next to it for the All Apps plug-in.
Writing, not just reading. client.createRequest("POST", path, JSON.stringify(body)) sends a body the same way. Typical calls from workflows are requesting a catalog item (POST /catalog/api/items/{id}/request), running a day-2 action on a deployment (POST /deployment/api/deployments/{id}/requests), and tagging. Each one starts an asynchronous request in VCF Automation, so read the request ID from the answer and poll its status with a bounded loop, as waitForTask does for vCenter in recipe 8.1.
Pipelines aren’t there. Aria Automation 8.x had Code Stream pipelines, which could call Orchestrator and be called from it. VCF Automation 9 doesn’t include pipelines (Broadcom KB 378424), so anything you used them for moves into workflows or into a CI system outside VCF.
See also
- 5.2 REST hosts and operations
- 8.5 Extensibility subscriptions
- 8.6 Workflows as catalog items
- Broadcom TechDocs: the VCF Automation API reference for your release
- CloudBlogger, the author’s blog: Add a VCF Automation 9 host to Operations Orchestrator using Library workflow, Simplest Way to generate Bearer Token in Orchestrator for Aria Automation, End-to-End VCF Automation Token Generation via REST APIs.
