APIs are a powerful way to interact programmatically with products, such as vROps Cloud, which has a rich set of APIs and detailed Swagger-based documentation. Looking around for documentation, I found a blog from VMware Staff Cloud Solutions Architect Cosmin Trif, but I wanted a bit more, here's what I came up with.
First, log into your VMware Cloud Services portal.
![](https://static.wixstatic.com/media/b4065e_a9c6f5472b214b1c92a9881203dbba64~mv2.png/v1/fill/w_980,h_508,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_a9c6f5472b214b1c92a9881203dbba64~mv2.png)
Select your name top right, then click MY Account.
![](https://static.wixstatic.com/media/b4065e_db94fd23f4e946afa3d83ba212a71b76~mv2.png/v1/fill/w_980,h_535,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_db94fd23f4e946afa3d83ba212a71b76~mv2.png)
Generate an API Token first which you will then exchange for an API Authentication Token. This will allow you to interact securely with the vROps Cloud API. Click GENERATE TOKEN.
![](https://static.wixstatic.com/media/b4065e_756603c5a9d8436e9790355ca74688da~mv2.png/v1/fill/w_980,h_774,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_756603c5a9d8436e9790355ca74688da~mv2.png)
Give it a name, adjust the Token TTL as you wish, select the desired Roles and the other options you might want, then click GENERATE.
![](https://static.wixstatic.com/media/b4065e_2532cc144eaa480b8dc9746a3a5900d3~mv2.png/v1/fill/w_980,h_505,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_2532cc144eaa480b8dc9746a3a5900d3~mv2.png)
You now have your API Token which you can exchange for an API Authentication Token. Once done click CONTINUE.
Back on your API Tokens tab, click the ? bubble, it'll tell you how to exchange your API Token for an API Authentication Token.
![](https://static.wixstatic.com/media/b4065e_6733ba15633f41faaa08f7b37b18bc65~mv2.png/v1/fill/w_980,h_356,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b4065e_6733ba15633f41faaa08f7b37b18bc65~mv2.png)
There are several different ways to interact with the vROps Cloud API, the two most popular are via REST Clients: cURL and Postman. Documentation on each can be found here. cURL is is on my vROps master node, so I'm going to run commands from there.
To exchange the API Token for an API Authentication Token, run this command:
curl --location --request POST 'https://console.cloud.vmware.com/csp/gateway/am/api/auth/api-tokens/authorize' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'refresh_token=your_api_token_goes_here'
This will return a JSON string in the following format, documentation can be found here.
{
"id_token",
"token_type",
"expires_in",
"scope",
"access_token",
"refresh_token”
}
Now that we have our API Authentication Token, let's explore the endpoints and data available to us via the API. API documentation is available via the URL of your vROps Cloud instance. For example, if the URL of your instance is https://www.mgmt.cloud.vmware.com, the API reference is available from: https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/doc/swagger-ui.html. Mine looks something like this:
![](https://static.wixstatic.com/media/b4065e_05dcc27762ec4187bc5504aed0eb8fdc~mv2.png/v1/fill/w_980,h_668,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_05dcc27762ec4187bc5504aed0eb8fdc~mv2.png)
The Swagger-based documentation for the vROps Cloud API is quite robust, with examples, Try it out features, and more. Let's run a couple cURL commands, we'll get started by showing all the adapters we are running:
curl -X GET https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/api/adapters -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: CSPToken access_token_goes_here"
You'll get a JSON string like this:
![](https://static.wixstatic.com/media/b4065e_746cc0e4ea8b4ca89dbfa96e9fab90dd~mv2.png/v1/fill/w_980,h_382,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/b4065e_746cc0e4ea8b4ca89dbfa96e9fab90dd~mv2.png)
Maybe we'd like to determine the current user:
curl -X GET https://www.mgmt.cloud.vmware.com/vrops-cloud/suite-api/api/auth/currentuser -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: CSPToken access_token_goes_here"
You'll get a JSON string like this:
![](https://static.wixstatic.com/media/b4065e_4bae9746715d4364abc5f75b7aaa46a0~mv2.png/v1/fill/w_980,h_44,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/b4065e_4bae9746715d4364abc5f75b7aaa46a0~mv2.png)
There are more than 25 vROps Cloud API endpoints available, with GET, POST, PUT, PATCH, DELETE, and other available methods. If you're just getting started with APIs, here's a great video on Postman. VMware {code} is another great resource for Postman collections as well.
תגובות