Home VMwareAutomation Kickstart VMware Cloud on AWS API with PowerCLI

Kickstart VMware Cloud on AWS API with PowerCLI

by Mohamed Imthiyaz

Automate and manage your SDDCs running on VMware Cloud on AWS leveraging APIs. There are multiple ways to work with APIs, in this post we will see how can this be done from VMC Developer Center and via PowerCLI.

Let’s start with GUI – Developer Center

  1. Login to your vmc.vmware.com
  2. Click on Developer Center and go to API Explorer

3. Expand VMware Cloud on AWS and click General
4. Select your SDDC from the drop-down
5. For this test We will retrieve our SDDC information. 
6. Search for SDDC on right pane, expand it look for GET /orgs/{org}/sddcs/{sddc} . {org} & {sddc} will be prefilled for you as you have already selected your SDDC in step 4, Hit Execute and you can download or copy the response of the API call in json format.

API call via PowerCLI

To start with API you will need your API token (Refresh Token) if you don’t have your API token, please follow “Getting started with managing VMC on AWS via PowerCLI” or generate API token from HERE.

Unlike GUI here we need an additional token which is Access Token (CSP Auth Token) that has to be generated with your API Token (Refresh Token), follow the steps

Open any text editor copy the below code to it and Replace xxxxx with your Refresh Token

$req_headers = @{accept='application/json'}
$req_body = 'refresh_token=xxxxxxxxxxxxxxxx'
$cspBaseURI = 'https://console.cloud.vmware.com/csp/gateway/'
$cspAPIAuthEP = 'am/api/auth/api-tokens/authorize'
$vmcBaseURI = 'https://vmc.vmware.com/vmc/api/'
$csp_resp = Invoke-RestMethod -Method POST -Uri $($cspBaseURI+$cspAPIAuthEP) -Headers $req_headers -Body $req_body
$cspAuthToken = $csp_resp.access_token; $cspAuthHeaders = @{'csp-auth-token'="$cspAuthToken"}

Open PowerShell, copy and paste all 6 lines and your Access Token (CSP Auth Token) is Generated

Let’s put it to test and call the same API we test on GUI, there are multiple ways to do it.

I have set my ORGID and SDDCID variable, you can do the same

Example 1

Using Invoke-RestMethod

Invoke-RestMethod -Method GET -Uri https://vmc.vmware.com/vmc/api/orgs/$orgid/sddcs/$sddcid -Headers $cspAuthHeaders -Body $req_body

Example 2

Using curl, this will give you the json output

 curl -H "csp-auth-token:$cspAuthToken" https://vmc.vmware.com/vmc/api/orgs/$orgid/sddcs/$sddcid

Please add your comments below if you have any queries or feedback regarding the same.

You may also like

Leave a Comment