Skip to content

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

  1. Connect to the WebUI service by clicking on the already open tab, or clicking on the WebUI link on the topology landing page.

    WebUI

    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.

  2. 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:

    https://192.168.0.12
    
  3. When prompted, enter the credentials from the ATD dashboard. When prompted with the SSL Certificate error, click Advanced, and then Accept the Risk and Continue.

    CertError

  4. Once logged in, you will see the eAPI Explorer.

    eAPI Explorer

Verification

To verify we are successfully authenticated, lets run a test command and see the result.

  1. In the command window which says Enter Commands, enter the following command and click Submit Post Request.

    show interfaces
    
    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:

    Command Verify

    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.

  1. Lets try configuring a VLAN. Enter the following in the command block section and hit Submit Post Request

    vlan 1000
    name test
    

    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?

  2. Now lets try configuring a VLAN with the required commands.

    configure
    vlan 1000
    name test
    

    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.

  1. Type the following command to verify if the VLAN was configured correctly.

    show run sec vlan
    

Test

Success

Lab Complete!