The Orchestrator REST API
The Orchestrator Client is a web page that calls a REST API, and that API is open to you too. Everything the client does, from listing workflows to importing a package, is a call under /vco/api that a script, a pipeline, or another product can make. Recipes 6.4 and 6.5 already used it to move packages. This recipe steps back and shows how to find your way around it: where its reference lives, how to log in to each kind of Orchestrator, and how to read the objects you’ll want to act on in recipe 7.2.
Getting ready
vco01.vmw.labwith vSphere authentication (recipe 1.4).- A vSphere SSO user for scripts,
svc-vcfguide@vsphere.local, made a member ofOrchestratorAdmins. A named account for scripts keeps their runs apart from yours in the logs. With vSphere authentication the only Orchestrator role is administrator (recipe 1.3); recipe 7.2, There’s more, covers accounts with less. - The workflow List VMs by name in VCF Orchestrator Guide/Chapter 3, with one input
namePattern(string) and one outputvmNames(Array/string), from recipe 3.2. Run it once in the client, so it has a run to find. - A Linux or macOS shell with
curlandjq, and the lab’s CA certificate saved asvmw-lab-ca.pem. - For part C, an account in the Provider Consumption organization of VCF Automation that can open its Orchestrate tab (recipe 1.1).
How to do it
A. Open the reference
- Browse to
https://vco01.vmw.lab/vco/api/docs. The API’s reference opens as a Swagger UI page, grouped into services such as Workflow Service, Workflow Run Service, Packages Service, and Policy Service. The same reference is on Broadcom’s developer portal, at VCF Operations Orchestrator API (latest), when you’re away from the server. - Click Authorize, enter
svc-vcfguide@vsphere.localand its password under basic authentication, and close the dialog. - Expand Workflow Service, open
GET /workflows, and click Try it out, then Execute. Below the button, the page shows thecurlcommand it sent, the response code200, and a JSON list of workflows.
Browser at https://vco01.vmw.lab/vco/api/docs: the Swagger UI page with Workflow Service expanded, GET /workflows opened after Execute, showing the generated curl command, response code 200, and the start of the JSON body. Blur the Authorization header.
/vco/api/docs/swagger-ui/index.html on VCF Automation; check whether /vco/api/docs redirects there on a standalone appliance, and which authentication methods the Authorize dialog offers.B. Call it from a script
- Save this file as
vro-env.sh. It asks once for a user name and password, and defines a smallvrofunction that adds the address, the CA certificate, the credentials, and the JSON header to every call:
# Source this file: . vro-env.sh# Sets up the vro function for one Orchestrator.VRO="${VRO:-https://vco01.vmw.lab/vco/api}"CACERT="${CACERT:-vmw-lab-ca.pem}"
if [ -z "${VRO_TOKEN:-}" ]; then read -r -p "User for $VRO: " VRO_USER read -r -s -p "Password: " VRO_PASS; echofi
# Usage: vro METHOD PATH [extra curl options]vro() { local method="$1" path="$2"; shift 2 local auth if [ -n "${VRO_TOKEN:-}" ]; then auth=(-H "Authorization: Bearer $VRO_TOKEN") else auth=(-u "$VRO_USER:$VRO_PASS") fi curl --fail-with-body --silent --show-error --cacert "$CACERT" \ "${auth[@]}" -H "Accept: application/json" \ -X "$method" "$@" "$VRO$path"}- Load it and check who you are:
. vro-env.shvro GET /about | jq .vro GET /users | jq ./about answers anyone. It gives the version and build of the server, as in recipe 1.1. /users needs a login, and describes the user you logged in as, so it’s a quick test of your credentials. A wrong password gives 401.
On 9.1.1, /users answers with the login name, the display name, the domain, the groups and the role:
{ "admin-rights": true, "role": "ADMINISTRATOR", "member-groups": [], "display-name": "svc-vcfguide", "login-name": "svc-vcfguide", "domain": ""}–fail-with-body prints the JSON error of a 401.- Find the workflow by name. List calls take a
conditionsquery parameter, and the answer is a list of links, each carrying the object’s attributes as name and value pairs:
vro GET '/workflows?conditions=name=List%20VMs%20by%20name' \ | jq -r '.link[] | [(.attributes[] | select(.name == "id") | .value), (.attributes[] | select(.name == "categoryName") | .value)] | @tsv'The output is one line: the workflow’s ID and its folder, Chapter 3. Copy the ID into a variable:
WF_ID='paste-the-id-here'Terminal: . vro-env.sh with the user prompt, vro GET /about | jq . showing version 9.1.1, then the /workflows?conditions=name=… call printing the ID of List VMs by name and Chapter 3.
On 9.1.1, conditions=name=List VMs by name matches the exact name, conditions=name~List VMs matches part of it, and each link’s attributes include id, name and categoryName. Add keys=id&keys=name&keys=categoryName to get only those three attributes.
- Read the workflow’s inputs and outputs. These are what a script must send when it starts the workflow (recipe 7.2):
vro GET "/workflows/$WF_ID" \ | jq '{name, version, inputs: ."input-parameters", outputs: ."output-parameters"}'{ "name": "List VMs by name", "version": "…", "inputs": [ { "name": "namePattern", "type": "string" } ], "outputs": [ { "name": "vmNames", "type": "Array/string" } ]}- List the workflow’s runs with their state, newest first:
vro GET "/workflows/$WF_ID/executions" \ | jq -r '[.relations.link[] | select(.rel == "down") | .attributes | from_entries] | sort_by(.startDate) | reverse | .[:5][] | [.id, .state, .startDate] | @tsv'The run you started in the client is there, completed, with its ID and start time.
On 9.1.1 the runs are under relations.link, as links with rel = down, next to two links that aren’t runs (up and add). Each run has the attributes id, name, state, startDate, endDate, startedBy and currentItemDisplayName, and relations.total counts them. The list comes oldest first, and sortOrder didn’t change that in the lab, so the filter sorts by startDate itself. maxResult is honoured, but it keeps the oldest runs, so don’t use it to get the latest ones.
C. The Orchestrator embedded in VCF Automation
The embedded Orchestrator doesn’t take a user name and password on its API. It takes a bearer token issued by VCF Automation for your organization. You get one in two steps: create a long-lived API token once, then exchange it for a short-lived access token whenever a script runs.
- Log in to the Provider Consumption organization portal at
https://auto.vmw.lab, open the user menu at the top right, and choose My Account. On API Tokens, click New, give the token a name such asvcfguide-scripts, and create it. Copy the token: it’s shown only once.
VCF Automation 9.1, Provider Consumption organization portal, user menu > My Account > API Tokens, the new token vcfguide-scripts just created, with the copy button and the warning that it won't be shown again (blur the token).
- Exchange it for an access token. Replace
<org>with the organization’s name as it appears in the portal’s address:
API_TOKEN='paste-the-api-token-here'export VRO_TOKEN="$(curl --fail --silent --show-error --cacert vmw-lab-ca.pem \ -H 'Accept: application/json' \ --data-urlencode 'grant_type=refresh_token' \ --data-urlencode "refresh_token=$API_TOKEN" \ 'https://auto.vmw.lab/oauth/tenant/<org>/token' | jq -r .access_token)"- Point the helper at the embedded Orchestrator and repeat steps 5 to 8. Because
VRO_TOKENis set,vro-env.shdoesn’t ask for a password, and sends the token instead:
export VRO='https://auto.vmw.lab/vco/api'. vro-env.shvro GET /users | jq ./oauth/tenant/<org>/token; whether the access token from that call is accepted by /vco/api on auto.vmw.lab as a bearer token; and how long it lasts. Community write-ups give one hour for the access token and 90 days by default for the API token.How it works
One API, two front doors. Every Orchestrator, standalone or embedded, serves the same API under /vco/api, and the client you click in uses it too. What differs is how you prove who you are, and that follows the authentication provider the server uses (recipe 1.3):
| Orchestrator | Authentication provider | What the API accepts |
|---|---|---|
Standalone, vco01.vmw.lab |
vSphere (recipe 1.4) | Basic authentication with an SSO user |
| Standalone | VCF Automation (recipe 1.5) | A bearer token from VCF Automation |
Embedded, auto.vmw.lab |
VCF Automation, always | A bearer token from VCF Automation |
On a standalone appliance with vSphere authentication, Basic authentication always works. Broadcom KB 440608 notes that the system property com.vmware.o11n.sso.basic-authentication.enabled only applies to Orchestrators integrated with VCF Automation, and that there’s no supported way to turn Basic authentication off on a vSphere-authenticated appliance. Protect the service account’s password like any other administrator password, and use HTTPS with a proper CA certificate, as vro-env.sh does with --cacert.
The API is the client’s permissions, not more. A call runs as the user it authenticates. It can see, run, and change only what that user can in the client, by the same roles and the same folder permissions. A script never needs a special API account, only a suitable ordinary one.
Resources and links. The API is organized around resources: /workflows/{id} is a workflow, /workflows/{id}/executions/{executionId} is one of its runs, /packages/{name} a package. List calls return links to those resources rather than the resources themselves, each with a few attributes such as the ID and name, so that a long list stays small. Follow a link’s href, or build the path from its ID, to get the full object. conditions filters a list on the server, which is faster and safer than downloading every workflow and filtering in jq.
JSON or XML. The API can answer in XML or JSON. Ask for JSON with Accept: application/json on every call, as the helper does, rather than relying on a default.
Tokens expire, API tokens don’t, for a while. The bearer token for the embedded Orchestrator is short-lived on purpose. A script asks for a new one each time it runs, and keeps only the API token, which lasts until its expiry date or until you revoke it. Treat the API token as a password: keep it in your pipeline’s secret store, never in a script or a Git repository.
/vco/api with the user name and password of a vRO user, whatever the server's authentication mode.There's more
Copy what the client does. The quickest way to learn a call is to watch the client make it. Open your browser’s developer tools on the Network tab, do the thing in the Orchestrator Client, and look at the request it sent: the path, the method, and the JSON body. That’s how you’ll find the format of an input in recipe 7.2 when the reference only says object.
The Orchestrator gateway in VCF Automation. VCF Automation 9.1 also has an Automation Orchestrator Gateway API, with paths such as /vro/workflows and /vro/runs, that reaches the Orchestrator integrations of an organization through VCF Automation. It uses query options such as $filter and $top rather than conditions. Use it when a VCF Automation project, rather than one Orchestrator, is the thing you’re scripting against. Its reference is linked from API Documentation in the VCF Automation user menu.
/vco/api-docs/modern-tenancy), which organization types offer it, and whether POST /vro/runs can run a workflow on the embedded Orchestrator with the same access token as part C.Don’t reach for -k. Many examples on the internet call Orchestrator with curl -k, which skips certificate checks. That also skips the only thing that tells your script it’s talking to the real server before it sends a password. Keep the CA certificate next to your scripts and pass it with --cacert.
The reference on the developer portal. Broadcom publishes the same API reference at developer.broadcom.com/xapis/vcf-operations-orchestrator-api/latest. It’s the one to bookmark: latest always opens the newest release (9.1.2 as this is written), and a version picker on the page opens 9.1 or 9.0 when your server is older. Every service from the Swagger UI in step 1 has its own page there, and each call has an example body and response. The links in this book’s See also lists point to it.
Read the change log before an upgrade. The API reference on the Broadcom developer portal has an API ChangeLog page per release. Check it before you upgrade an Orchestrator that scripts and pipelines depend on.
PowerShell. On Windows, Invoke-RestMethod does everything curl and jq do here, and returns objects you can filter with Where-Object. Recipe 7.2 shows it.
See also
- 1.3 Choosing an authentication provider, which decides how the API authenticates you.
- 6.4 Promoting content from development to production and 6.5 Signing and trusting packages, which use the API for packages.
- 7.2 Starting workflows from scripts, which uses
vro-env.shto run a workflow and read its result. - Broadcom developer documentation: VCF Operations Orchestrator API reference, its API security schema, and the Automation Orchestrator Gateway API 9.1.
- Broadcom TechDocs (VCF 9.0): Generating API tokens for the service provider account, for the API token and its exchange.
- Broadcom KB 440608: the Basic authentication property doesn’t apply to standalone instances.
- Broadcom community: Swagger for the Orchestrator API in VCF 9.0.
- CloudBlogger, the author’s blog: How to modify vRO Workflow description using REST, Generate vRO Workflow Runs Report in CSV.
