Simple eAPI request editor

This page lets you craft a single eAPI request, and explore the returned JSON. Note that this form creates real eAPI requests, so any configuration you perform will apply to this switch. Don't know where to start? Read the API overview or try one of these examples: Check version, Create an ACL, Show virtual router, or View running-config!

Request Viewer

Response Viewer

Interactive eAPI scripting environment

This page lets you interactively play with eAPI (a.k.a Command API), using the Javascript programming language. To use, write code in the scripting area below and then click "Run Script". You'll then see all requests, responses and script output in the console box below. Note that these script calls are real eAPI requests, so any configuration you perform over the API will apply to this switch.

Show API documentation

The Javascript library exposes a number of utilities and methods to help you write scripts.

To make requests, create and store a new EapiClient(). The returned object exposes a single method called runCmds(). The first parameter of runCmds() is a hash that conains the eAPI prameters. Once again, these are:

  • version (mandatory): a number containing the numeric version, should be 1 (mandatory).
  • cmds (mandatory): a list of command objects or strings that should be executed.
  • format (optional) the response format: either "json" or "text". This defaults to "json".
  • timetamps (optional): a boolean. If true, the response contains timestamps indicating how long it took to run each command. Defaults to false.
For example, a call to this function might look like var result = eapi.runCmd({version: 1, cmds: ["show version", "show hostname"]});. Note that this command is asynchronous! What is returned is a Javascript "promise", implemented by jquery.Deferred object. To use this object, set one or more of the following callbacks:
  • To access the result of the eAPI call, set the done() callback with a function that takes a single parameter: the data array, which contains an eAPI response object for each command in the request. For example, to access the result of a "show hostname" API call, you can write result.done(function(data) { var hostname = data[0]["hostname"] });.
  • To provide an error callback, implement the fail() callback. This is called with three parameters: the numeric JSON-RPC error_code, a string message, and the JSON data payload, which is a list containing an eAPI response for each command that was succesfully executed.

The library also provides a logMessage() function, which lets you print arbitrary text to the output console. It takes one or more arguments, and prints them all to the console.

Script Output: