Command API¶
This lab will demonstrate the on-switch Command API explorer feature. The Command API provides an interface to experiment with commands and view their request and response structure without having to write a script or program to test it with.
Preparing The Lab¶
-
Connect to the WebUI service by clicking on the already open tab, or clicking on the WebUI link on the topology landing page.
This will launch a Firefox instance in your browser located in your topology, not your laptop. Refer to the main ATD screen for the login password.
-
Once logged in to Firefox, to access the switch’s Command API, enter the management IP address of the device you want to connect to via HTTPS:
-
When prompted, enter the credentials from the ATD dashboard. When prompted with the SSL Certificate error, click
Advanced
, and thenAccept the Risk and Continue
. -
Once logged in, you will see the eAPI Explorer.
Verification¶
To verify we are successfully authenticated, lets run a test command and see the result.
-
In the command window which says
Enter Commands
, enter the following command and click Submit Post Request.Command Syntax
The full command should be used to work properly; shorthand commands, such as sh int do not work. Any API action is the same way. Technically, you can use the
AutoComplete
command to use shorthand, but it’s a good practice to use long form. When writing code it’s always important to think about the next person to look at it!When you successfully issue a command, notice what the response looks like:
Note
The format above is in JSON (JavaScript Object Notation). Every line has a key, and a value. This is why JSON is nice to use; it’s easy to reference and use key/value pairs.
Lab Tasks¶
Now that we have verified we can send API requests, lets try making some configuration changes.
-
Lets try configuring a VLAN. Enter the following in the command block section and hit Submit Post Request
What does the response viewer say? Note there’s an error, in this case:
"message": "CLI command 1 of 2 'vlan 1000' failed: invalid command"
If you were to log into the switch right now and issue that command without using an API, what would happen?
-
Now lets try configuring a VLAN with the required commands.
Just like if you were to login to a switch and issue those commands normally, the same applies here. The response should indicate a success now.
Test¶
Log into your switch, with a ssh session, or Console Access service.
To get to the ssh menu, type in the menu option ssh and press Enter. Next we will connect to leaf1, by typing leaf1 in
When prompted, enter the credentials from the ATD dashboard.
-
Type the following command to verify if the VLAN was configured correctly.
Success
Lab Complete!