Course Content
Spanning Tree
An overview of how switches become aware of other switches and prevent loops.
0/2
Multiple Spanning Tree Protocol (MST)
0/1
Advanced OSPF
The (OSPF) protocol scales well with proper network planning. IP addressing schemes, area segmentation, address summarization, and hardware capabilities for each area should considered when designing a network.
0/6
Introduction to Automation Tools  
To provide a high-level overview of some of the most common configuration management and automation tools that are available.
0/3
ENCOR Course
About Lesson

Application Programming Interface (API)

What APIs are, different types of APIs, and how they are used.

  • Northbound and Southbound APIs
  • REST APIs
  • Introduction to Postman
  • Data Formats (XML, JSON)
  • DNA Center APIs
  • vManage APIs

Northbound and Southbound APIs

  • A method of communicating with and configuring a network is the use of APIs.
  • Northbound APIs often used to communicate from a network controller to its management software.
  • The controller information being passed from the management software is leveraging a Northbound REST-based API. This traffic encrypted using TLS.
  • If a change to a switch’s configuration in the management software of the controller, those changes are then pushed down to the individual devices (routers, switches and WAPs) using a Southbound API and programmatic interface.

Representational State Transfer (REST) APIs

  • An API that uses REST is often referred to a RESTful API.
  • RESTful APIs use HTTP methods to gather and manipulate data.
HTTP Function Action Use Case
GET Requests data from a description Viewing a website
PPOST Submits data to a specific destination Submitting login credentials
PUT Replaces data in a specific destination Updating an NTP server
PATCH Appends data to a specific destination Adding an NTP server
DELETE Removes data from a specific destination Removing an NTP server
CRUD Function Action Use Case
CREATE Inserts data in a database or application Updating a customer’s home address in a database
READ Retrieves data from a database or application Pulling up a customer’s home address from a database
UPDATE Modifies or replaces data in a database or application Changing a street address stored in a database
DELETE Removes data from a database or application Removing a customer from a database
  • HTTP offers a consistent way to interact with APIs from multiple vendors.
  • HTTP functions are similar to functions that most applications or databases use to store/alter data.
  • These functions called “CRUD”.

Postman

  • One of the most important pieces of interacting with any software using APIs is testing.
  • Testing code helps ensure that dev are accomplishing the outcome that was intended when executing the code.
  • Many APIs require user authentication to gain access to utilize the APIs.
  • If a REST API call used to delete data, that data will be removed just as if a user logged in via the CLI and deleted it.
  • An application that makes it possible to interact with APIs using a console-based approach. Postman allows for the use of various data types and formats to interact with REST-based APIs.

Postman

  • The Postman application has various sections that you can interact with. The focus here is on using the Builder portion of the dashboard.
    • History – The history tab shows a list of all the recent API calls made.
    • Collections – API calls stored in groups, called collections, specific to a user’s needs.
    • New Tab – Each tab can have its own API call and parameters that are completely independent of any other tab.
    • URL Bar – Each tab has its own URL bar to be able to use a specific API. Remember that an API call using REST is very much like an HTTP transaction. Each API call in a RESTful API maps to an individual URL for a particular function. This means every configuration change or poll to retrieve data a user makes in a REST API has a unique URL—whether it is a GET, POST, PUT, PATCH, or DELETE function.

Data Formats XML and JSON

  • Two of the most common data formats used with APIs. Extensible Markup Language (XML) commonly used when constructing web services.
  • XML is a tag-based language. For example, <interface> and would be </interface>.
  • Inside the start tag and end tag, you can use different code and parameters.

  • The data structured so that it contains a section called “users,” and within that are four users:
    • root
    • Jason
    • Jamie
    • Luke

XML and JSON

  • JavaScript Object Notation (JSON) is much easier to work with than XML. It is simple to read and create.
  • JSON stores all its information in key/value pairs.
  • JSON uses objects for its format. Each JSON object starts with a { and ends with a }.
  • In this JSON code snippet, you can see that the first key is user, and the value for that key is a unique username, root.

HTTP Status Codes

Now that the XML and JSON data formats have been explained, it is important to circle back to using the REST API and the associated responses and outcomes of doing so.

HTTP Status Code Result Common Reason for Response Code
200 OK Using GET or POST to exchange data with an API
201 Created Creating resources by using a REST API call
400 Bad Request Request failed due to client-side issue
401 Unauthorized Client not authenticated to access site or API call
403 Forbidden Access not granted based on supplied credentials
404 Not Found Page at HTTP URL location does not exist or is hidden

 

DNA Center APIs

DNA Center controller expects all incoming data from the REST API to be in JSON format. The HTTP POST used to send the credentials to the DNA Center controller.   DNA Center uses basic authentication to pass a username and password to DNA Center Token API to authenticate users. This API used to authenticate a user to DNA Center controller to make additional API calls.   The key steps necessary to successfully set up the API call in Postman are as follows:

  • Step 1. In the URL bar, enter https://sandboxdnac.cisco.com/api/system/v1/auth/token to target the Token API.
  • Step 2. Select the HTTP POST operation from the dropdown box.
  • Step 3. Under the Authorization tab, ensure that the type is set to Basic Auth.
  • Step 4. Enter devnetuser as the username and Cisco123! as the password.
  • Step 5. Select the Headers tab and enter Content-Type as the key.
  • Step 6. Select application/json as the value.
  • Step 7. Click the Send button to pass the credentials to the DNA Center controller via the Token API.

DNA Center APIs

You can tell that the API call to the DNA Center controller completed successfully by receiving an HTTP status code 200. The Network Device API allows users to retrieve a list of devices that are currently in inventory that are being managed by the DNA Center controller. You need to prepare Postman to use the token that was generated when you successfully authenticated:

  • Step 1. Copy the token you received earlier and click a new tab in Postman. Step 2. In the URL bar enter https://sandboxdnac.cisco.com/api/v1/network-device Step 3. Select the HTTP GET operation from the dropdown box.
  • Step 4. Select the Headers tab and enter Content-Type as the key.
  • Step 5. Select application/json as the value.
  • Step 6. Add another key and enter X-Auth-Token.
  • Step 7. Paste the token in as the value.
  • Step 8. Click Send to pass the token to the DNA Center controller and perform an HTTP GET to retrieve a device inventory list.

DNA Center APIs (Cont.)

Within a few moments an API call can be used to gather that data for the entire network. When using APIs, it is common to manipulate data by using filters and offsets. If a user wants to leverage the Network Device API to gather information on only the second device in the inventory. This is where the API documentation becomes so valuable. In Postman, it is possible to modify the Network Device API URL and add ?limit=1 to the end of the URL to show only a single device in the inventory. It is also possible to add the &offset=2 command to the end of the URL to state that only the second device in the inventory should be shown. These query parameters are part of the API.

vManage APIs

There are various APIs available in SD-WAN and the vManage controller. With a SD-WAN API you need to provide login credentials to the API in order to be able to utilize the API calls. Some key pieces of information are necessary to successfully set up the API call in Postman:

  • The URL bar must have the API call to target the Authentication API
  • The HTTP POST operation is used to send the username and password to Cisco vManage
  • The Headers Content-Type key must be application/x-www-form-urlencoded
  • The body must contain keys with the j_username devnetuser and thej_password Cisco123!

 

 

Other useful information:

Join the conversation