The NSX REST API supports several authentication schemes to secure management plane interactions. While the web interface handles credentials automatically, API consumers must manually implement authentication headers or session management. This article provides the precise technical requirements for HTTP Basic and Session-Based authentication.
HTTP Based Authentication
HTTP Basic Authentication sends credentials in the Authorization header as a Base64-encoded string in the format:
Authorization: Basic <base64(username:password)>
cURL Example
curl -k -u admin:password https://<NSX_MANAGER>/api/v1/logical-ports
Here, the -k flag tells cURL to skip verification of the server’s self-signed SSL certificate.
Recommended Secure Usage
For better security, verify the server certificate using a trusted Certificate Authority (CA):
curl --cacert /home/me/certs/rootca.crt -u admin:password https://MANAGER/api/v1/logical-ports
Supported Usernames
Local user: admin
Remote user: user@domain (the domain must match a configured VIDM or LDAP identity source)
Session-Based Authentication
Session-based authentication uses a login API to create a session and returns a session cookie. This cookie, along with an X-XSRF-TOKEN header, must be included in subsequent API requests.
1. Create a Session
Send credentials as form data (application/x-www-form-urlencoded) to /api/session/create:
curl -k -c cookies.txt -D headers.txt -X POST -d 'j_username=USERNAME&j_password=PASSWORD' https://MANAGER/api/session/create
Session cookies are saved to cookies.txt
Response headers (including X-XSRF-TOKEN) are saved to headers.txt
2. Use the Session
Include the cookie and XSRF token in subsequent requests:
curl -k -b cookies.txt -H "grep -i X-XSRF-TOKEN headers.txt | tr -d '\r\n'" https://MANAGER/api/v1/logical-ports
Session behaviour
3. Destroy a Session
To explicitly end a session:
curl -k -b cookies.txt -H "`grep -i X-XSRF-TOKEN headers.txt | tr -d '\r\n'`" -X POST https://MANAGER/api/session/destroy
Using POSTMAN to run the API calls
For Basic Authentication
Run the desired API call, with the Authorization as Basic Auth, where you can add the username and password.
For SESSION based Authentication
1. Create a SESSION :
2. USE the SESSION :
3. Destroy SESSION :