Getting Started with the NSX-T API and Postman

Wether you like it or not, the API plays a significant role when installing, configuring, and managing an NSX-T environment. Sooner or later you will be facing tasks that either require you to use the API or simply are much faster to complete using the API.

Luckily, with the right tools and some preparation, getting started with API-based management isn’t all that hard.

In this article I will show you how I set up REST API Client Postman for interaction with the NSX-T API.

Step 1 – Download and install Postman

A pretty obvious first step. You need to download and install Postman. Get it from https://www.getpostman.com/.

Step 2 – Create a Postman environment

After you’ve installed Postman, you should create a Postman environment for your NSX-T environment.

An environment in Postman is a place where you create and store variables with their values. These can then be used within API requests. Using environment variables will save you a lot of time!

To create an environment in Postman choose File > New and select Environment.

Give your environment a name and add the following variables:

VariableValue
nsx-manager-fqdnyour-nsx-manager-fqdn
nsx-manager-useryour-nsx-manager-user
nsx-manager-passwordyour-nsx-manager-password

For example:

Step 3 – Download the NSX-T OpenAPI specification

The NSX-T API is described in the OpenAPI format and you can download the OpenAPI specification file using a GET request in Postman.

Create a new GET request in Postman with the following URL:

https://{{nsx-manager-fqdn}}/api/v1/spec/openapi/nsx_api.json

As you can see you immediately make use of your newly created environment variable nsx-manager-fqdn. Just don’t forget to select the environment (in the top right corner) so that Postman knows where to fetch it’s value.

You also need to authenticate when connecting to the NSX-T API. This is configured under Authorization. Select Basic Auth from the Type list.
Instead of entering the NSX-T credentials in the Username and Password fields, you type a “{” and select the nsx-manager-user variable from the list that pops up:

Tick the Show Password box and then repeat this little “trick”, but now select the nsx-manager-password variable instead:

Click the Send button to fetch the OpenAPI specification for the NSX-T Manager API

Step 4 – Import the NSX-T OpenAPI specification

The specification is downloaded and visible in the body of the GET request:

Copy the contents of the request body by clicking on the two overlapping squares icon in the right corner and wait until it says Copied to clipboard which can take a couple of seconds:

Next, click the Import button in the upper left corner of the Postman application window and select Paste Raw Text. Paste the contents of the request body into the text box and then click the Import button:

After a couple of seconds you should see a collection called NSX-T Manager API containing 1163 requests (NSX-T 2.4.1):

Step 5 – Search and replace

All requests in the OpenAPI specification file use nsxmanager.your.domain as the NSX Manager FQDN. You want to use your {{nsx-manager-fqdn}} environment variable of course. Let’s fix that.

Click the magnifying glass icon in the bottom left of the Postman application window:

Type nsxmanager.your.domain as the string to search for and click the Find button. For NSX-T 2.4.1 it should find 1163 occurrences of this string under Collections:

A bit further down you’ll find a REPLACE WITH field. Here you enter the variable {{nsx-manager-fqdn}} and tick the Select all box. Now hit the Replace in 1163 selected button to replace the string in all requests.

Step 5 – Configure Authorization

You also want all of the API requests in the NSX-T Manager API collection to perform basic auth using the nsx-manager-user and nsx-manager-password variables that you defined in your Postman environment. This is configured at the collection level.

Right-click the NSX-T Manager API collection and select Edit:

Click the Autorization tab and select Basic Auth from the Type list. Enter {{nsx-manager-user}} as the Username and {{nsx-manager-password}} as the Password. Click the Update button:

All 1163 requests will now use these “parent” authorization settings.

Conclusion

It takes some minutes to set up, but by using a Postman environment and the NSX-T OpenAPI specification you will save yourself a lot of time in the future.

Next time you need to configure or deploy something in NSX-T you could perhaps use one of the 1163 API requests in Postman. After all, everything is already set up. At least you should feel a little less hesitant when turning to the NSX-T API interface from now on.

By the way. If you don’t feel like going through all of these steps you can download the Postman environment and the NSX-T collection files created in this article. Just import them into your Postman, modify the variables in the environment so they fit your NSX-T environment, and you should be good to go.

1 Comment

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