api

WN Blog 020 – Postman Variables

In our previous blog (please start there), we were typing in all the site IDs, WLAN IDs, API authentication tokens & Mist API HTTPS URL manually. It’s no fun, right?

Since we’re likely to interact with Mist API using one Mist account, we’ll probably use one API key globally.

Additionally, we’ll probably interact with specific organisations, sites or attributes (like WLANs) that are more ‘local’. It might be separate clients in a managed service environment or separate sites under one org. Whatever it is, it makes sense to think of it as a specific, local environment, something that is not global.

Surprise! We can define our variables on both “Environment” and “Global” level in Postman.

API token will be set as a “Global” variable, and all the rest attributes we used so far will be defined inside an “Environment” called “Mist WiFi Ninjas”.

Mission:

  • Use Global and Environment Variables to make our lives easier

Environment Variables

First, note that we are not using any environments right now.

Our request still has long, manually pasted streams representing site, WLAN and Mist API URL.

Postman 
File Edit View 
Import 
Runner 
Q Filter 
History 
% MyWorkspace • 
GET httpswapi.mist.corn"api/...• 
Invite 
GET httpswapi.mist.com//api.. 
Collections 
GET httpswapi.mist.conwapi/.... 
APIs 
Untitled Request 
Clear all 
Save Responses 
Today 
https://api mist.com.'/api/vl 'sites,'0fc98886-fb c48ef-b905-819200d57d54/wIans,'a88d6cdd-6aa5-4eb20... 
Upgrade 
Save 
Headers (9) 
Test Results 
Visualize 
Body 
pre•request Script 
VALUE 
Value 
Tests 
Settings 
DESCRIPTION 
Description 
status: 2000K Time: 1 71 ms 
Cookies 
Code 
GET 
GET 
PUT 
https://api.mist.com//api/vl 'sites/Ofc 
Params 
98886-fb 1 c-48ef-b905-819200d57d5 
4/wlans/a88d6cdd-6aa54eb2-8cd9-fb 
Authorization 
Query Params 
https://api.mist.com//api/vl 'sites/Ofc 
98886-fb 1 c-48ef-b905-819200d57d5 
4,'wlans/a88d6cdd-6aa5-4eb2-8cd9-fb 
Key 
Body Cookies Headers (16) 
Size: 451 KB 
Bulk Edit 
Save Response 
{(wIan_5ghz)} 
((wlan_5ghz)) 
{(m nsJ 
((wlan_5ghz)) 
https:,'/api mist.com//api/vl 'sites/Ofc 
98886-fb 1 c48ef-b905-819200d57d5 
https//api mist.com//api/vl 'sites/Ofc 
98886-fb 1 c48ef-b905-819200d57d5 
https„'/api mist.com//api/vl "'sites/Ofc 
98886-fb 1 c-48ef-b905-819200d57d5 
Pretty Raw 
Preview 
"class": "best effort" 
"overwrite": false 
id": "d2b94bf9-22bø-4af1-aød1-68e162fbe199" 
"dtim": 2, 
"hide ssid": false, 
"acct servers": 
"created time": 
"disable_uapsd" : 
[1, 
1557492085, 
false, 
"allow mdns": false,

Let’s create our new Environment and name it “Mist WiFi Ninjas”

GET https:,',/agi.rr 
Untitled Request 
Headers (8) 
MANAGE ENVIRONMENTS 
GET https:'%vj•_mi 
)/vvlans/K• 
GET 
An environment is a set of variables that allow you to switch the context of your requests Environments can be shared 
Mist WiFi Ninjas 
Send 
ok 
Save Response 
bet%'een multiple workspaces. Learn more about environments 
Mist WiFi Ninjas 
Globals 
Share 
Import

Define our variables on the Environment level

Postman 
File View 
History 
Today 
Help 
GET 
Untitled Request 
GET 
% My Workspace 
GET https:napinis con-Ina; 
Invite 
GET https:.'/api_mist.com//api„, 
Mist WiFi Ninjas 
https://api.mist.com//api/vl/sitesJOfc98886fb 1 c 4e 52 •8, , , 
Send 
https:.'/api.mist.com//api/vl'sites/Of 
Params 
9200d57di 
GET 
"wIans/aggd6cdd-6aaS-4eb2-8cd( 
I 'sites," 
98886-fbl 9200d5 
4/wIans/aggd6cdd-6aaS-4eb2-gc 
((y.'Ien_Sghzp 
gg8g6-fh 1 c-4gef-hg05-g1 9200dS 
4/wIans/e88d6cdd-6ae54eb2-8c 
https://api.rmst.com//api/vl'site 
MANAGE ENVIRONMENTS 
Environment Name 
Mist WiFi Ninjas 
VARIABLE 
'ave Response 
INITIAL VALUE O 
a88d6cdd-6ass-4eb2-... 
0 08886- 
https://api.mist.com//... 
CURRENT VALUE O 
Persist All 
Reset All 
wlan 
site 
uc ton 
a88d6cdd-6ea5-4eb2-8cdg-fb8731ab18e2 
0 08886- lc-48e- 905-819200 57 54 
https://api.mist.com//api/vl 
Add a new variable

Global Variables

Go to Globals

File Edit View, 
History 
Today 
• My Workspace • 
GET https:\' 
Untitled Request 
Invite 
GET "mist}}. 
Mist WiFi Ninjas 
https://ap...X 
Clear all 
GET 
1 1 9200d57d54,'wlans/ s-4eb2-E 
Send 
PUT 
PUT 
PUT 
PUT 
PUT 
PUT 
vrwIan_5ghzp 
jJwIan_SEh7P 
https://api.mist.comnapi/vl/site 
a88d6cdd-6aa5-4eb2-8c 
https://epi.mist.cum,qapi/vl/site 
98885fb1c48eft905819200d5 
4,'wIans/a88d6cdd-6aa5-4eb2-8c 
' 'nlan_5ghz} 
unlan_5ghzp 
UwIan_5ghzp, 
https://api.mist.com//api/vl/site 
https://api.mist.com//api'vl/sire 
• 'wIans,'a88d6cdd-6aa54eb2-8c 
https://api.mist.comnapi/vl/site 
https://api.mist.com//api/vl/site 
ggg86-fh1c-4gef-hgos-g1g200ds 
• 'wIans/a88d6cdd-6ea5-4eb2-8c 
https://api.mist.comnapi/vl/site 
qggg6-fh1 q200dS 
https://api.mist.com//api/vl/site 
9ggg6-fb1 c-48ef-b90S-819200dS 
https://api.mist.com//api/vl/site 
woods 
d/"' lans/a88d6cdd-6aa5-4eb2-8c 
https://api.mist.com//api/vl/site 
https://api.mist.comnapi/vl/site 
d/wIans/a88d6cdd-6aa5-4eb2-8c 
https://api.mist.com//api/vl/site 
• 'wIans/a88d6cdd-6aa5-4eb2-8c 
https://api.mist.comnapi/vl/site 
98886 f'01c48ef4-,905819200d5 
MwIans/a88d6cdd-6aa5-4eb2-8c 
https://api.mist.comnapi/vl/site 
• iwIans/a88d6cdd-6aa5-4eb2-8c 
https://epi.mist.com,qapi/vl/site 
98885fb1c48eft905819200d5 
MANAGE ENVIRONMENTS 
An environment is a set of variables that allow you to switch the context of your requests. Environments can be shared 
between multiple Learn more about environments 
Mist WiFi Ninjas 
Globals 
Share 
Import 
Yesterday

Define your global token.

Remember to include “Token ” prefix before pasting actual token value.

MANAGE ENVIRONMENTS 
Global variables for a workspace are a set of variables that are always available with 
can be viewed and edited by anyone in that workspace, Learn more about globals 
Globals 
VARIABLE 
to en 
Add a new variable 
INITIAL VALUE O 
CURRENT VALUE O

Replace our manual values with variables

%stman 
File Edit View 
Q Filter 
History 
Import 
Collections 
Runner 
AP IS BETA 
Clear all 
GET https:/,'api.... 
Untitled Request 
GET 
httpswapi.... 
My Workspace • Invite 
GET httpswap... 
GET {Cmistmsi.... 
Mist WiFi Ninjas 
GET {{mist»/si... 
Save Responses 
Today 
Pa rams 
0 
Code 
Headers (9) 
Test Results 
Visualize 
Body 
Cookies 
Presets 
GET 
GET 
GET 
PUT 
PUT 
PUT 
GET 
GET 
{Cm ({site_ ns} 
{(wlan_5ghz)) 
{(wIan_5ghz}) 
{(wlan_5ghz)) 
https://api.mist.com//api/vl/sites/ofc 
98886.fb1 c48ef.b905-819200dS7dS 
4/wIans/a88d6cdd-6aa 54eb2-8cdg-fb 
httpsWapi mist.com/,'api/vl'sites/Ofc 
98886-fbl c48ef-b905-819200dS7dS 
4/wIans/a88d6cdd-6aa 54eb2-8cdg-fb 
{Km 
{(wlan_5ghz)) 
{Cm nsJ 
{(wlan_5ghz)) 
{(wlan_5ghz)) 
https:/fapi 
98886-fb1c48ef-b905-819200d57d5 
https:/fapi mist.com/,'api/vl'sites/Ofc 
98886-fb1c48ef-b905-819200d57d5 
https://api 
98886-fbl c48ef-b905-819200d57d5 
https://api.mist.com//api/vl'sites/Ofc 
98886-fbl c48ef-b905-819200d57d5 
https://api.mist.com//api/vl'sites/Ofc 
98886-fbl c48ef-b905-819200d57d5 
https://api.mist.com//api/vl"sites/Ofc 
98886-fbl c48ef-b905-819200d57d5 
4/wIans 
Authorization 
Headers (2) 
Authorization 
Content-Type 
Key 
Temporary Headers (7) O 
Body Cookies Headers (16) 
Pre-request Script 
VALUE 
"token}) 
application/json 
Value 
DESCRIPTION 
Description 
Time: 687ms 
Bulk Edit 
Status: 2000K 
Size: 452 KB 
Save Response 
Pretty 
Raw 
Preview 
"class": 
"best effort" 
"overwrite": false 
"org_id • 
"d2b94bf9-22bØ-4af1-aØd1-68e162fbe199", 
"dtim": 2, 
"hide ssid": false, 
"acct servers": 
"created time": 1557492085, 
"disable_uapsd": false, 
"allow mdns": false, 
"apply_to": "site", 
"app_limit": { 
"apps" • 
"enabled": false, 
"wxtag_ids . 
. "a88d6cdd-6aa5-4eb2-8cd9-fb8731ab18e2" , 
"vian id": 
"wxtag_ids " : 
null, 
"mxtunnel id": null, 
"ssid": 
"vlan_pooling": false, 
"wlan limit down": 20ØØØ, 
"wxtunnel id": null,

Enjoy Postman environment that is easier on the eyes! Easy peasy lemon squeezy!

With love,

WiFi Ninjas x

WN Blog 019 – Getting Started with Mist API

Let’s face the truth. We can’t avoid dev stuff in WiFi forever! REST API, Python, JSON, Ansible and whatever else is needed – here we come!

It’s time. This is day 1 of our studies!

The mission for today? Actually we have a few 🙂

  • Prepare the environment to work with Mist REST API using Postman
  • List all WLANs created in WiFi Ninjas site using Mist API using GET
  • Narrow the list down to a specific WLAN – “WiFiNinjas(.)(.)”
  • Rename “WiFiNinjas(.)(.)” WLAN to “WiFiNinjasTitties” using PUT

Extreeeemely complicated, we know 😉

Let’s assume everyone knows what the API is. In case it’s not the case, here is a quick read:

https://www.howtogeek.com/343877/what-is-an-api/

Mist (and most other Enterprise solutions) use REST:

https://restfulapi.net/

Lastly, from Mist Documentation:

https://www.mist.com/documentation/category/api/

Steps to complete our little task below!

Install Postman

You can get it here:

https://www.getpostman.com/downloads/

Generate Token

Token is needed so the Mist Dash can authorize us to access API.

Log into Mist Dash, then go to and hit ‘POST’:

https://api.mist.com/api/v1/self/apitokens

All 
api.mist.com/api/vl/self/apitokens 
Lab Natilik WN 
CWNP Gml 
GM T LN Is 
Django REST framework 
Self ! Getall Create Apitoken 
Getall Create Apitoken 
POST /api/vl/self/apitokens 
HTTP 2øØ 0K 
Allow: POST, OPTIONS, GET 
Content—Type: i cation/ j son 
Vary: Accept 
"created time": 1574783690, 
"last used • • : 
null, 
" pc cml , 
OPTIONS 
GET 
Media type: 
Content: 
application/json

If you hit ‘POST’ again, new token will be generated!

Take note of the “key” – it’s our token.

Let’s assume we want to list created WLANs in the test ‘WiFi Ninjas’ site.

Check API URL to list Site WLANs

Mist API is nicely documented. You can go to Mist API documentation page to check the URL for everything that’s possible using RESTful API:

https://api.mist.com/api/v1/docs/Home

api.mist.com/api/v1/docs/Home 
Natilik 
CWNP Gml 
GM 
TOC 
Overview 
Overview 
permiesion 
Query 
Rate Limit 
Mist GithUb Repo 
Authentication 
Login 
Privileges 
Register 
AudiU.ogs 
Integration 
Site 
WIan 
Map
C api.mist.corn/api/vl /docs/Site#wlan 
Lab Natilik WN 
CWNP Gml 
WIan 
Wireless LAN definition 
WIans are the wireless networks created under a site. 
Base URI 
Example 
"ssid"• "corporate" 
"auth": { 
"type": "psk 
// type 
is psk 
"enable 
mac auth": false, 
GM

We now know the syntax to get our WLANs.

Get Org ID and Site ID

Next we need to know the “WiFi Ninjas” Site ID to check against.

Go to Mist Dash. You can get Org ID and Site ID from the browser URL:

All Lab Natilik WN 
Inbox - mac.deryng@gmaiLcorn X 
Mist *stems Administration 
Access Points 
• WiFi Ninjas 
Mist University I Al for IT Mist AP 
SITE ID 
IP Address 
x 
C •a0d1 
CWNP Gml @ G A GM T LN 
ORG ID 
site Buckton Fields 
MAC Address 
pp 
MiSt 
Monitor 
Marvisw 
O) Clients 
Access Points 
Switches 
Location 
Analytics 
CJ Network 
organization 
WIFI NINJAS 
o 
Filter 
Site I API I Mist 
NO. Clients 
X Getall Create Apito 
uptime 
There are no APS found in this site 
Claim your Access Points by providing claim codes 
Claim APS

We now have everything we need to list our WLANs in ‘WiFi Ninjas’ site!

Use obtained API token, WLAN GET URL and Site ID to list the WLANs

  • Create new GET Request by hitting ‘+
  • Type https://api.mist.com//api/v1/sites/<siteID>/wlans into request URL
    • Ensure to include https:// prefix!
  • Go to ‘Headers‘ tab and specify (type in) Authorization (use Token obtained in previous steps in VALUE fields; ensure to include key word ‘Token ‘ before pasting in the actual token!) and Content-Type (type ‘application/json’ in VALUE field)
  • Hit ‘SEND
O Postman 
File Edit View 
Q Filter 
History 
Help 
Import 
Collections 
Runner 
APIs BETA 
Clear all 
My Workspace • 
Invite 
NO Environment 
GET https•.//api.mist.com//api/vl/sit.., • 
Untitled Request 
(D Save Responses 
Today 
https://api.mist.com//ag 
O GET 98886fb1c48ef.b905-8 + 
4/"' lans 
May 8 
Params 
Authorization 
upgrade 
Save 
Cookies Code 
presets 
Headers (2) 
Authorization 
Content-Type 
Key 
Temporary Headers (7) O 
Body Cookies Headers ( 1 6) 
Headers (9) 
Test Results 
Visualize 
Body Pre-request Script 
Tests 
VALUE 
Token UTEmqoKcpxImnGodssHzozcn8Sk7PCcm. 
application/json 
Value 
status: 2000K 
DESCRIPTION 
Description 
Time: 673ms 
Bulk Edit 
Size: 8.45 KB 
Save Response 
Pretty Raw 
Preview 
"class": "best effort", 
"over"Arite": false 
"org_id": "d2b94bf9-22be-4af1-aød1-68e162fbe199", 
"dtim": 2, 
"hide 55id": false, 
"acct_servers": t], 
"created time": 1557492085, 
"disable_uapsd": false, 
"allow mdns": false, 
"apply_to"• "site", 
"app_limit": { 
"enabled": false, 
"apps" • 
"wxtag_id5": O 
: "a88d6cdd-6aaS-4eb2-8cd9-fb8731ab18e2" , 
"vlan id": 20, 
"wxtag_ids": null, 
"SSI t" 
v an_poo Ing : 
"wlan limit dcmn": 2øøøe, 
"wxtunnel id": null, 
"auth serwers nas id": " 
false, 
"site id • 
". "efc98886-fb1c-48ef-b9ø5-81920edS7dS4", 
"disable Hmm": false, 
"airwatch": { 
"username" . 
"api_key"• " , 
"console url": " 
"password" • " 
"enabled": false 
"schedule": {

Note the “id” of “WiFiNinjas(.)(.)” WLAN

Copy WLAN “id” to our GET URL

*jstman 
File Edit View 
Import 
Runner 
APIs 
Clear all 
My Workspace • 
Invite 
No Environment 
History 
Collections 
GET httpswapi.mist.com"api/vl/sit... • 
Untitled Request 
GET httpswapi.mist.com"api/vl/sit... • 
Save Responses 
Today 
httpswapi.mist.com.'/api/vl 'sites,'0fc98886-fb 1 c-48ef-b905-819200d57d54/wIan . 
Send 
https://api.mist.com//api/vl 'sites/Ofc 
c-48ef-b905-819200d57d5 
4/wlans 
https://api.mist.com//api/vl 'sites/Ofc 
988864b 1 c-48ef-b905-819200d57d5 
4/wlans/a88d6cdd-6aa54eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
98886-fb 1 c-48ef-b905-819200d57d5 
4/wlans/a88d6cdd-6aa54eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
98886-fb 1 c-48ef-b905-819200d57d5 
4,'wlans/a88d6cdd-6aa54eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
98886-fb 1 c48ef-b905-819200d57d5 
4,'wlans/a88d6cdd-6aa5-4eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
1 9200d57d5 
4,'wlans/a88d6cdd-6aa5-4eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
1 c48ef-b905-819200d57d5 
4,'wlans/a88d6cdd-6aa5-4eb2-8cd9-fb 
https://api.mist.com//api/vl 'sites/Ofc 
1 c48ef-b905-819200d57d5 
4/wlans 
params 
Authorization 
Headers (9) 
Test Results 
Visualize 
Body 
pre-request Script 
VALUE 
Tests 
Code 
GET 
GET 
PUT 
Settings 
Save 
Cookies 
Presets 
Headers (2) 
Authorization 
Content-Type 
Key 
Temporary Headers (7) O 
Body Cookies Headers ( 1 6) 
Bulk Edit 
Token UTEmqoKcpxlmnGodssHZOZCn8Sk7PC 
application/json 
Value 
status: 200 0K 
Description 
Time: 176ms 
size: 8.5 KB 
Save Response 
P retty 
Raw Preview 
Yesterday 
May 8 
"template åd": null, 
leøøe 
"90s": { 
"class": "best effor•t" 
' false 
"org_åd 
"d2b94bf9-22be-aaf1-aød1-68e162fbe199", 
"dtim": 2, 
"hide ssid": false, 
"acct serwers : 
"created tine . 
"disable_uapsd" 
1557492085, 
. false, 
"allow mdns": false, 
"apply _ to": "site" , 
"app_limit": { 
• 'enabled": false, 
• 'apps": 
"wxtag_ids 
a88d6cdd-6aa5-1eb2-8cd9-fb8731ab18e2

We should now see the details of just “WiFiNinjas(.)(.)” WLAN.

PS. We love that (.)(.) suffix!

Change WLAN name

Let’s rename “WiFiNinjas(.)(.)” to “WiFiNinjasTitties”! 🙂

Since we’re changing WLAN config, we’ll use PUT this time.

Change request type to PUT, go to “Body” tab, ensure “JSON” type is selected and write down lines that you want changed between curly brackets.

Note, that there is no comma at the end of the line.

You can now refresh your Mist Dash or GET the WLAN info via API to check if the name was changed.

Worked like charm! 🙂

What’s Next?

Finally, we can use Postman to translate our actions into code (we’ll stick to Python), that can be used in scripts.

That’s it!

We have successfully listed all Mist WLANs, then narrowed it down to one WLAN and finally we’ve changed the name of that WLAN. All with REST API GET and PUT requests – how cool!

With love,

WiFi Ninjas x