API Call to Enable Mist AP Name Broadcast
In this blog post, we will see how we can make a simple API Call to the Mist cloud in order to have all APs, supporting a Wi-Fi network, broadcast their name.
We usually enable this feature when we are about to do a Wi-Fi site survey. This allows us to see the AP names in our survey software and allows us to produce better reports.
In this article, we will make this API call using the following methods:
- Within Postman
- Within a python script
BEFORE
Here is what a Wi-Fi scanner would look like when the AP do not broadcast their name:
As you can see, the “Device Name” field is empty.
PREPARING THE API CALL
If we want the APs to broadcast their name, we have to modify at least one of the WLAN profile broadcasted by our APs. Then, we need to enable the “Hostname Information Element” feature. The AP will then add an information element, containing the AP name, to each beacon that it sends out to advertise that specific WLAN.
If we take a look at Mist’s API documentation, we can see that we would need to use the following API call to modify a WLAN object (I am changing the properties of a WLAN profile defined in a configuration template at the org level):
PUT https://api.mist.com/api/v1/orgs/:org_id/wlans/:wlan_id
So we can now see that we will need to gather the following IDs to make the AP call:
- Org ID
- WLAN ID
Note: if you are trying to make this call at a site level (and not at the org level), you might want to use the site API endpoint.
And here is what the URL of the API call looks like when I add my own IDs:
PUT https://api.mist.com/api/v1/orgs/22bfc07a-8591-432e-8825-92593049db0d/wlans/8e9ec8e0-30c4-482d-a0ba-593a2996d013
But wait, it is not totally done. Since we are sending a PUT, we need to specify which properties of the WLAN object we are modifying. In our case, we want to set the hostname_ie property to True. This will indicate to the Mist cloud that we want to have the AP broadcast their name.
So in order to do it, we have to include a JSON formatted text within the body of our API Call that will indicate that we want to set the hostname_ie property to True. It should look like this:
{"hostname_ie": True}
You should now have all the specific information required to make the API call.
Of course, you will also need your Mist token which will allow you to interact with the Mist cloud and make API calls. If you want to know how to retrieve your Mist token, take a look at this video: Mist – Setup Your First API Call.
SEND THE CALL USING POSTMAN
Postman is an application that you can use to make API calls. It is a nice way to do it via a user interface. If you don’t have postman yet, feel free to download and try it out yourself: https://www.postman.com/downloads/
You can create a new API Call within the application by navigating to “File > New Tab”.
You will have to configure the following elements in order for the API Call to be successful:
- Specify your token in the HTML headers
- Specify the content to be JSON in the HTML headers
- Specify that you want to send a PUT request
- Specify the URL describe above including your Org ID and WLAN ID
- Specify the JSON text describe above in the body of the request
Here is what it should look like when you send out the request:
You can then click on “Send” to make the API Call. If everything goes well, you should receive an HTML 200 code back from the Mist cloud. You should also see the updated WLAN object properties (including the hostname_ie property set to True).
SEND THE CALL USING PYTHON
Of course, you can make this API call within a python script (which is my preferred method).
Here is the code you could use (make sure you use your own org ID, wlan ID and token):
import requests url = "https://api.mist.com/api/v1/orgs/YOUR_ORG_ID/wlans/YOUR_WLAN_ID" body='{"hostname_ie": true}' headers = { "Content-Type": "application/json", "Authorization": "Token YOUR_TOKEN" } response = requests.request("PUT", url, headers=headers, data=body) if response.status_code == 200: wlan_properties = json.loads(response.text) print("The APs will now be broadcasting their name!") else: print(f"Something went wrong with the API call: {response.status_code}")
Here is what it looks like when you execute it (make sure you have the requests module installed):
AFTER
Here is what the Wi-Fi scanner will look like once the APs are broadcasting their names:
That’s it! And you could do the same thing to disable it as well by setting the hostname_ie property to False.
If you are thinking about network automation. the idea would be to include this API call into a pre-survey and post-survey script that you would run before and after a site survey to validate configurations and prepare the infrastructure for the survey.
ADDITIONAL RESOURCES
- Video to help you setup your first Mist API call: Mist – Setup Your First API Call
- Video to help you send an API call within a python script: Mist – API Call within Python Script
- Mist API documentation: https://api.mist.com/api/v1/docs/Home
- Mist documentation on broadcasting AP name: Using an AP in Survey Mode