Python - Basic API Access with Mist Wi-Fi

Python - Basic API Access with Mist Wi-Fi
Mist-API-Architecture

The Mist access points were designed with API first. The information you're able to retrieve from their API is quite impressive. It's enough for you to build your own dashboard, if you dare to take that leap.

The Mist API architecture is simple. It starts with the REST API client, which in this example, is my computer running a script. That request is made via HTTPS to the Mist cloud and processed. In return, the Mist API sends a response.

https://www.mist.com/documentation/mist-api-architecture/

Here's a simple script that makes a request for the WLANs I have enabled. I then print it out the result to screen.

import json
import requests

site_id = '<your-site-id>'
url = "https://api.mist.com/api/v1/sites/{}/wlans".format(site_id)

headers = {
  'Authorization': 'Token <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 )

Here is the output:

% python3 get_wlans.py
SSID: D-NET  Enabled: True 	 VLAN: 2
SSID: CTS 	 Enabled: True 	 VLAN: 2