I was recently doing some work where I needed to access the APIs for the VMware Cloud Services Platform (CSP). As the name suggests, CSP is where customers can manage access, billing and consumption of the various VMware SaaS offerings including VMware Cloud on AWS (VMC) and VMware Hybrid Cloud Extension to just name a couple.

CSP also provides a RESTful API (Swagger documentation here) which enables customers and partners to automate all aspects of the CSP UI. Although my use of the CSP API is quite small, I figure it would useful to share the overall workflow in case others were interested in consuming the full CSP API.

The first thing you need is to retrieve the API Refresh Token which can be found by going to "My Account" in CSP and then navigating to the API Tokens as shown in the screenshot below. If you do not see a refresh token, simply generate one.



Once you have this refresh token, you will need to perform a POST to /am/api/auth/api-tokens/authorize to get back a CSP Access Token which will be used to authenticate yourself and be able to interact with the CSP APIs. To demonstrate this workflow, I have create two sample scripts below which takes a refresh token and returns the CSP Access Key and then perform a GET on /slc/api/definitions?expand=1 to use the key to list all CSP services (simliar to what you see when you first login to the CSP).

PowerShell

Here is an example PowerShell module VMware.CSP.psm1 which provides two functions: Get-CSPAccessToken and Get-CSPServices to interact with the CSP APIs:

Import-Module VMware.CSP.psm1

Get-CSPAccessToken -RefreshToken $RefreshToken

Get-CSPServices

Bash (cURL)

Here is a Shell script vmware-list-csp-services.sh which leverages cURL and jq to interact with CSP API:

./vmware-list-csp-services.sh $REFRESH_TOKEN