Back to Basics: Using Postman’s Environments and Tests with vRealize Automation

Most of the time I work with the vRealize Automation API through vRO Actions. Occasionally I have the need to make a change to the system which requires using the API. One such example is modifying the session timeout, as written by Gary at https://garyflynn.com/post/vrealize-automation-85-increase-session-timeout.

For something quick and simple like this I would use the excellent Postman client and a simple workflow. However, I recently took delivery of a new machine and had to set this up again as it wasn’t in my collection of requests.

Environment

In Postman, create a new environment for vRealize Automation and configuration the following variables:

Populate the FQDN and login details, then click Add to save the environment. Make sure the environment is selected in the top-right of the client.

Refresh Token

Open a new tab and set the following:

Method POST
URL https://{{va-fqdn}}/csp/gateway/am/api/login?access_token
Authorization None (Inherit auth from parent)
Headers Accept: application/json Content-Type: application/json
Body {
  “username”: “{{username}}”,
  “password”: “{{password}}”,
  “domain”: “{{domain}}”
}

If entered correctly, the variables (va-fqdn, username, password and domain should all be highlighted orange).

Click on the Test tab and enter the following:

var response = pm.response.json();
pm.environment.set("refresh_token", response.refresh_token);
view raw test1.js hosted with ❤ by GitHub

The above code will parse the response we receive, strip out the refresh token and set the environment variable with this value.

Click Send. You will notice that in the bottom pane, on the Body tab, a refresh token has been returned. You should also see this value in your environment variables by clicking on the eye icon to the right of your environment name.

Access Token

Create another tab, this time with the following details:

Method POST
URL https://{{va-fqdn}}/iaas/api/login
Authorization None (Inherit auth from parent)
Headers Accept: application/json Content-Type: application/json
Body {
  “refreshToken”: “{{refresh_token}}”
}

Use the following for the test:

var response = pm.response.json();
pm.environment.set("access_token", response.token);
view raw test2.js hosted with ❤ by GitHub

Click Send. You will notice the access token has been stored as a variable.

Make Your API Call

Open another tab, this time to make the API call of your choosing. I will use Gary’s post as an example:

Method POST
URL https://{{va-fqdn}}/iaas/api/configuration-properties?apiVersion=2021-07-15
Authorization None (Inherit auth from parent)
Headers Authorization: Bearer {{access_token}} Content-Type: application/json
Body {
  “key”: “SESSION_TIMEOUT_DURATION_MINUTES”,
  “value”: “1440”
}

In the above example, I have set my session timeout to twenty-four hours. Hope this helps!

One thought on “Back to Basics: Using Postman’s Environments and Tests with vRealize Automation

  1. Pingback: vExpert Cloud Management May 2022 Blog Digest - Möbius Business Technologies Ltd.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.