To conclude the Postman section, let us use the same example from the NX-API Sandbox and send a request to get the image version.
Remember, you found the class of the object to be boot:Image
. As a quick refresher, classes are a combination of packages and methods; package:method
.
Every thing is also represented as an MO in the system and can be identified by a unique distinguished name (DN).
You first must get an authentication token from the switch using the special MO aaaLogin
. In Postman, click the plus (+) button to create a new request. Make this a POST. In the URL field, use the URL below:
https://10.15.6.12/api/mo/aaaLogin.json
Next, click the Body, then click raw. While still on the same line of the application, select the Text dropdown and select JSON (application/json) as the message format. Type or copy the JSON below into the text area. Click the Send button to perform the POST request.
{
"aaaUser": {
"attributes": {
"name": "admin",
"pwd": "cisco.123"
}
}
}
Example from Pod01:
This should return a 200 OK and an authentication token for the switch as shown in the graphic below.
Example from Pod01:
You can see the acquired authentication tokens in the Cookies tab and the Headers tab in the graphics below. This can now be used to make subsequent requests to the switch.
Example from Pod01:
Depending on whether you are dealing with classes or DNs, the URL format used can be represented as follows:
The first request leverages the class boot:Image
. Remove the colon(:) between the package and the method to use the class name in a request.
The class for the request would be bootImage
. Create a new request in Postman by clicking the plus (+) and copying or typing the URL below into the URL field.
Notice the use of class within the URL. Make this request a GET. Then click Send to issue the request.
https://10.15.6.12/api/class/bootImage.json
Example from Pod01:
The response above matches the NX-API Sandbox from the previous lab section, but now let us examine how to use the DN and query the MO directly.
From the class request above, the output provides the DN of the object, sys/boot/image
.
Create a new request in Postman by clicking the plus (+) and copying or typing the URL below into the URL field. Notice the change to use the mo instead of class within the URL. Make this request a GET.
Then click Send to issue the request.
https://10.15.6.12/api/mo/sys/boot/image.json
Example from Pod01:
The request yields the same result. It's important to recognize, even though this was a simple example, the same techniques can be used for other objects as they are enabled within the system, i.e. features enabled such as OSPF, BGP, etc.