Getting Started with the Cloud Automation Services API

Getting started with the Cloud Automation Services API is a pretty smooth affair. Nonetheless, it is helpful to get a few pointers on the way, which is exactly what this post is for. The first thing to do is authenticate, but before we do that, let’s make sure that you know where to go in order to find the API calls that you want to make.

The best place to start when it comes to working with the Cloud Automation Services API is with the official documentation.
The Swagger specs for the services can be found at:

IaaS API
Blueprint API
Deployment API
Code Stream API
Service Broker API

Authenticating

In order to do anything useful with the API, you first need to authenticate. To do this, you need to get your API token.

Cloud Assembly OAuth Token

This can be retrieved from within your Organisation panel, as shown in the image above. Note that if you haven’t yet generated an API token, you will have a button to do so.

To authenticate and exchange your API token for a bearer token, simply POST to https://api.mgmt.cloud.vmware.com/iaas/login with a body of


{"refreshToken": refresh_token }

An example of the curl:


curl -X POST 'https://api.mgmt.cloud.vmware.com/iaas/login' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ "refreshToken": api_token }'

Here is a flow that is completely reusable (with your own API token of course) to assign the bearer token to an environment variable.


export api_token=0747w9h5-eb3a-4cd7-98e5-154c41cd1e85
export bearer=`curl -X POST 'https://api.mgmt.cloud.vmware.com/iaas/login' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ 'refreshToken': '$api_token' }' | jq -r '.token'`

Having the bearer token as an environment variable means that I can then re-use my header block for all of my calls in a repeatable manner. Here are a few examples, straight from the documentation listed above.

Returning one or more deployments

curl 'https://api.mgmt.cloud.vmware.com/deployment/api/deployments' -H 'Accept: application/json' -H 'Authorization: Bearer '$bearer'' | jq '.results[0]'

List all Pipelines

curl 'https://api.mgmt.cloud.vmware.com/pipeline/api/pipelines' -H 'Accept: application/json' -H 'Authorization: Bearer '$bearer''

Instantiating a Pipeline Execution

curl -X POST 'https://api.mgmt.cloud.vmware.com/pipeline/api/pipelines/e20273bb1fa9a475575bf448d046a/executions' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$bearer'' -d '{}'

Creating a Project

curl -X POST 'https://api.mgmt.cloud.vmware.com/iaas/projects' -H 'Content-Type: application/json' -H 'Authorization: Bearer '$bearer'' -d '{ 'name' : 'Foo', 'description' : 'Bar'}'

While curl is useful, working with the API in a more efficient manner could be achieved via an SDK, or some sort of API wrapper. Stay tuned if you’re interested in that!

This post is part of a series.
Part 1 - Introducing VMware Cloud Automation Services
Part 2 - Basic Blueprinting in Cloud Assembly
Part 3 - Blueprint Versioning in Cloud Assembly
Part 4 - This Article
{ % include footer.html % }