Getting Started with JSON API for Mellanox Switches

Version 7

    JavaScript Object Notation (JSON) is a machine-to-machine data-interchange format which is supported in MLNX-OS CLI.

    The JSON API allows executing CLI commands and receiving outputs in JSON format which can be easily parsed by the calling software.





    In order to get started with Mellanox Switch JSON API, a software tool that can perform operations such as GET/POST/PUT/DELETE is required.

    Various tools can be used. For example:


    The example below utilizes the I'm Only Resting tool.



    Make sure you have management access to Mellanox's switch in your network.



    1. Download and install the I'm Only Resting tool.


    2. ssh login to the switch to enable JSON API.

    switch (config) # json-gw enable


    Save the configuration.


    3. Perform the login operation in order to get the session cookie:


    Set the proper username and password.


    For example:

    • URL: http://<switch-ip-address>/admin/launch?script=rh&template=login&action=login
    • Select POST operation
    • Headers: Content-Type: application/x-www-form-urlencoded
    • Body: f_user_id=admin&f_password=admin (or another user)



    4. Copy the session cookie from the Response header in order to use it next for the POST requests.


    5. Once you have the session id, add a cookie to the header and create a command (cmd) request in the body.


    URL: http://<switch-ip-address>/admin/launch?script=json



    Content-Type: Content-Type: application/x-www-form-urlencoded

    cookie: session=<Session ID>


    Body Structure:


    "cmd": "<CLI command>"



    Body example:


    "cmd": "show interfaces ethernet status"




    You can use a POST operation to run a command. For example: "show interfaces ethernet status"




    JSON via Switch WebUI

    It is possible to run the JSON API via the switch's WebUI. Click on Setup > JSON API and enter the command: "show interfaces ethernet status"




    The full list of commands and more examples can be found in MLNX-OS User Manual.