vRA 8.1 – Quick Tip – API Authentication

Hello!

In this short blog post we will cover how to authenticate with the vRA 8.1 API.

For vRA 8.1 the steps to get your Bearer Token are twofold:

  1. First you need to retrieve your Refresh Token
  2. With that Refresh Token you can get your Bearer Token

This is apparently due to a ‘missing internal state’ according to the vRA 8.1 API Programming Guide found here.

Curious which API calls vRA 8.1 supports? Find more information below:

Let’s get started:

  1. Get your favourite REST API tool (Postman, Curl, …)
  2. Execute the following REST API call
    URL: https://<vRA8.1-URL>/csp/gateway/am/api/login?access_token
    Method: POST
    Headers: 'Content-Type: application/json'
    Body: {
    	"username": "username",
    	"password": "password",
    	"domain": "System Domain | AD Domain"
    }
    CURL Command:
    curl --location --request POST 'https://<vRA8.1-URL>/csp/gateway/am/api/login?access_token' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    	"username": "username",
    	"password": "password",
    	"domain": "System Domain | AD Domain"
    }'
  3. If everything goes well you will retrieve the Refresh Token as shown below:
    Screenshot 2020-06-26 at 10.13.57
    Save the Refresh Token.
  4. Next up let’s retrieve our Bearer Token from the vRA 8.1 IaaS API:
    URL: https://<vRA8.1-URL>/iaas/api/login
    Method: POST
    Headers: 'Content-Type: application/json'
    Body: {
            "refreshToken": "refresh_token_here"
    }
    CURL Command:
    curl --location --request POST 'https://<vRA8.1-URL>/iaas/api/login' \
    --header 'Content-Type: application/json' \
    --data-raw '{
            "refreshToken": "refresh_token_here"
    }'
  5. The result will be the following:
    Screenshot 2020-06-26 at 10.21.46
    You now have a Bearer Token!

 

Let’s test it out.

With the following API Call we will retrieve deployment details and request the resource details of this deployment:

  1. Quickly lookup a Deployment and retrieve a Deployment ID from the vRA 8.1 UI:
    Screenshot 2020-06-26 at 11.35.02
  2. To retrieve this Deployment’s Details via API, perform the following:
    URL: https://<vRA8.1-URL>/deployment/api/deployments/<deployment-id>?expandResources=true
    Method: GET
    Headers: 'Content-Type: application/json' \
    'Authorization: Bearer <Bearer-Token>' \
    Body: 
    CURL Command:
    curl --location --request GET 'https://<vRA8.1-URL>/deployment/api/deployments/<deployment-id>?expandResources=true' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer <Bearer-Token>' \
    --data-raw ''
  3. This should result in similar output below:
    Screenshot 2020-06-26 at 11.32.21

Hopefully it helped!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s