CTS 208: Introduction to APIs
Application Programming Interface: communication protocol or interface used to interact between different pieces of software.
In networking, you could have an API available to interact between a Wireless Controller and a script coded by the network admin.
APIs make it very easy to interact with our networking equipment to configure, operate and monitor them.
In the networking world, these API communications are often established over the HTTPS protocol and are categorized as RESTful APIs. It stands for REpresentational State Transfer. It is a very popular API framework for web services built on HTTP.
REST is popular because it is fast, simple, scalable and easy to work with.
Why use an API?
* Custom dashboards* Automation* Installs* Configuration* Testing* Troubleshooting
How can I use an API?
Vendors usually provide extensive API documentation that will tell you how to use them and which data to expect. Sometimes, you have to enable this access (Meraki).
You can then use applications such as Postman that will help you to design your API calls.
Communications are secured and will require some sort of authorization (using a token or API Key). This key will be referenced in every request via a request header.
Methods (API Calls)
* GET: returns the value of a resource or a list of resources (Ex: get a list of online APs)* PUT: adds a new resource (Ex: create a new site)* POST: updates a resource (EX: updating the name of an AP)* DELETE: remove a resource (Ex: removing a user)
Responses – Status and Error Codes
You will get a response from your API calls. These responses use the standard HTTP status codes:
* 400: Bad Request* 401: Unauthorized* 403: Forbidden* 404: Not found* 429: Too Many Requests* 500: Internal Server Error* 503: Service Unavailable
If everything goes well, you should receive a 200 status code as well as the response to your query (if it was a GET query). This response is generally organized with the JSON format. It becomes easier to read and parse it in a script.
This format can also be specified in the headers: Content-Type: application/json
Important Things to consider
* Limitation of number of calls* 5 calls per second for Meraki* 5000 calls per hour for Mist (to validate)
Sample Scripts
Rowell’s Script
import json
import requests
site_id = '<your-site-id>'
url = "https://api.mist.com/api/v1/sites/{}/wlans".format(site_id)
headers = {
'Authorization': 'Basic <your-token>'
}
response = requests.request("GET", url, headers=headers)
r = json.loads(response.text)
for wlans in r:
wlan_name = wlans['ssid']
wlan_enabled = str(wlans['enabled'])
wlan_vlan = str(wlans['vlan_id'])
print("SSID: " + wlan_name, "\t Enabled: " + wlan_enabled, "\t VLAN: " + wlan_vlan )
Sample Output
% python3 get_wlans.py
SSID: D-NET Enabled: True VLAN: 2
SSID: CTS Enabled: True VLAN: 2
François’ Script
#!/usr/bin/env python3
import time
import json
import requests
def main():
org_id = '<org-id>'
site_id = '<site-id>'
token = '<your-token>'
You May Also Like

Darrers podcast - Ràdio Pineda
Ràdio Pineda

Arroe Collins Like It's Live
Arroe Collins

O Antagonista
O Antagonista

WSJ What’s News
The Wall Street Journal

Up First from NPR
NPR

Notiziario Radio Veneto24
Radio Veneto24

Sicilia Local News
Radio Taormina

The Megyn Kelly Show
SiriusXM

Talking Barents Говорит Баренц
The Barents Observer

Kan Hourly News כאן רשת ב חדשות השעה
Mr. Mp3
Community discussion