NSX RESTful API allow to interact with NSX manager, read the state of the NSX and change configuration. Some of NSX task can only be done via API and not GUI.
The protocol using to communication with the NSX Manager is HTTPS, over secure channel we send request and response data in XML format.
In this blog post we will use Mozilla web browser as REST client.
Install Mozilla REST Client:
REST Client can download from:
To install the REST Client Click on the “Open Menu” Button and Then click on the “Add-ons” button:
Click on “Install add-on from file”:
Import the REST Client file from the folder you download and click “Install”.
Note: Mozilla browser will restart
To open the REST Client click on the Red button:
One time configuration of REST Client:
Choose “Basic authentication”
Type in NSX Credential for NSX Manager and Click Okay.
Select from menu “Headers” and “Custom Header”
Type the Username and Password for NSX Manager and Click Okay.
In name type “Content-Type”.
In Value type: “application/xml”
Click Save to favorite and Okay
Now we can start to work with REST Client.
There are few different Method to read and configure the NSX Manager.
The frequent tasks we will work with REST Client are:
GET: to read information from NSX Manager
POST: to change configuration in NSX Manager
DELETE: to DELETE configuration in the NSX Manager
In the URL we need to type the NSX Manager URL:
Our first exercise will be to configure Logical Switch.
Create Logical Switch with API
To do this we will need to know which transport zone will use this logical switch.
In my lab we have two transport zone Global-Transport-Zone and DMZ-Transport-Zone.
NSX as different scope ID to represent different transport zone.
Assuming we would like to configure the logical switch in DMZ-Transport-Zone we need to find out what is the Transport zone scope.
Finding this scope can be done with API call:
Click on the red “SEND” button.
The “status code” 200 mean we successfully get the API information
After click on the Response Body we got results for DMZ-Transport-Zone we get vdnsope-2
For Global-Transport-Zone we get vdnsope-1
Since we want to configure this logical switch on DMZ-Transport-Zone we will use vdnsope-2 in the POST API Call.
Create Logical switch in DMZ-transport-Zone:
The Method: POST
Body is the Payload of the actual configuration.
<name>DMZ-Logical-Switch-01</name> <description>Created via REST API</description> <tenantId>virtual wire tenant</tenantId> <controlPlaneMode>UNICAST_MODE</controlPlaneMode> </virtualWireCreateSpec>
“415 Unsupported Media Type”
The reason for this is typo in “content type”
My typo configuration is: Con: application/xml instead of writing Content-Type: application/xml
Another issue can lead to same error:
Ensure that the SSL certificate used by NSX Manager is accepted by the client [browser or fat client] before making the call. By default, NSX Manager uses self-signed certificate that is accepted by the user. In such cases, ensure that the NSX Manager certificate is accepted before making the REST API call
The REST APIs use a HTTP response message to inform clients of their request’s result (as defined in RFC 2616). 5 Categories Defined:
1xx: Informational Communicates transfer protocol-level information.
2xx: Success indicates that the client’s request was accepted successful.
3xx: Redirection indicates that the client must take some additional action in order to complete their request.
4xx: Client Error This category of error status codes points the finger at clients.
5xx: Server Error The server takes responsibility for these error status codes.
After fixing this typo and click on “SEND” we get status 201
Each logical switch as unique virtual wire id:
Form NSX GUI, Logical Switch tab we can see we successfully crested the Logical switch.
Link to official API guide