12-06-2022 05:26 AM
Hello,
I am trying to learn APIs for the first time whilst also trying to get a specific job done and need a little guidance.
We have some WiFi monitoring and reporting software that can see all the BSSID's flying around, but at the moment it cant give us any clear info about them. In order to do that I need to feed it an xml that will tell it which BSSIDs belong to which AP's (and the associated SSID and the band).
We have hundreds of AP's so going through the meraki portal and copying this data manually is painful - I'm hoping I can pull this data with a GET request?
So far I have setup postman with a new environment and set a API key and baseURL variables.
At this point I wanted to turn to some pre-made examples from here but its v0 not v1
https://documenter.getpostman.com/view/7928889/SVmsVg6K#9019f8d0-a1db-4eb1-b45d-c348dc800e32
will these examples be unusable in v1? If so is there a v1 set of basic API's like this somewhere? In any case I coudlnt find something that provided the data fields I'm after 😞
Also - we have lots of different networks and Id need this info for each network - does that complicate things? IE can you do a API call on all networks or is it per network etc?
Thanks!
Solved! Go to Solution.
12-07-2022 07:01 AM
Quick and dirty example.
I just tested it on an org with over 12000 active AP-BSSIDs (took 2-3 minutes), it works ok.
You'll need Python 3 and the Meraki Python library installed.
Most of the code is setting things up and error detection, the action all happens in just a few lines.
If you want to add extra output fields, just edit the print statement.
import os
import sys
import meraki.aio
import asyncio
#import the org id and api key from the environment
#or you could hard code them, but that's less desirable
ORG_ID = os.environ.get("PARA0")
API_KEY = os.environ.get("PARA1")
async def processAp(aiomeraki: meraki.aio.AsyncDashboardAPI, ap):
try:
# get list of statuses for an AP
statuses = await aiomeraki.wireless.getDeviceWirelessStatus(ap['serial'])
except meraki.AsyncAPIError as e:
print(f'Meraki API error: {e}', file=sys.stderr)
sys.exit(0)
except Exception as e:
print(f'some other error: {e}', file=sys.stderr)
sys.exit(0)
for bss in statuses['basicServiceSets']:
if bss['enabled']:
print(f"{ap['name']},{bss['ssidName']},{bss['bssid']},{bss['band']}")
return
async def main():
async with meraki.aio.AsyncDashboardAPI(
api_key=API_KEY,
base_url='https://api.meraki.com/api/v1/',
print_console=False,
output_log=False,
suppress_logging=True,
wait_on_rate_limit=True,
maximum_retries=100
) as aiomeraki:
#get the wireless devices
try:
aps = await aiomeraki.organizations.getOrganizationDevices(ORG_ID, perPage=1000, total_pages="all", productTypes = ["wireless"])
except meraki.AsyncAPIError as e:
print(f'Meraki API error: {e}', file=sys.stderr)
sys.exit(0)
except Exception as e:
print(f'some other error: {e}', file=sys.stderr)
sys.exit(0)
# process devices concurrently
apTasks = [processAp(aiomeraki, ap) for ap in aps]
for task in asyncio.as_completed(apTasks):
await task
if __name__ == '__main__':
asyncio.run(main())
12-06-2022 05:29 AM
ooh, actually - is this what I need?
https://developer.cisco.com/meraki/api-v1/#!get-device-wireless-status
12-06-2022 05:54 AM
ok cool, just realised that this page will actually run the API for you as well! 😛
It runs ok but I have to specify the serial number of a specific AP. Is there a way to to run it against all AP's in all networks?
12-06-2022 06:14 AM
found this - /organizations/{organizationId}/deviceStatuses
now just to figure out where to get teh org id from? I found old posts about a v0 api call but the actual post with an explanation isnt up anymore 😘
12-06-2022 06:18 AM
12-06-2022 06:28 AM
aah but it doesn't show what i need 😞
need a "connection stats" call for organisation - which I cant find atm
12-06-2022 07:17 AM
I use https://developer.cisco.com/meraki/api-v1/#!get-network-wireless-connection-stats
Assuming you want details at SSID level, You need to call it on each SSID on each network (that has at least one AP) in the organization.
To get the list of networks... https://developer.cisco.com/meraki/api-v1/#!get-organization-networks
To see if a network has any APs, check the devices... https://developer.cisco.com/meraki/api-v1/#!get-network-devices
To find the SSIDs in a network... https://developer.cisco.com/meraki/api-v1/#!get-network-wireless-ssids
12-06-2022 07:26 AM
I have written plenty of custom applications using the API and what I found to be very useful is to get all your networks and devices (switches, access points) into a back end SQL database. As these do not change very often no point in running APi calls to get this info to pass to another API
I then grab the device info and network ID from database and then run the needed API to do what ever I need to do
Again for monitoring and reporting, I write to a back end SQL database and use PowerBI to create fancy graphs
Example of what I have written
AP channel utilisation. An alert sent out when utilisation is high. A PowerBI report to show AP utilisation over time
AP client connections to diffrent SSID's, or Access Point, again written to back end SQL database and PowerBI reports to see usage over period of time can be grouped into network ID, SSID . An alert sent out if client counts is high so can be proactive as end users complain about performance.
12-06-2022 08:00 AM
I think an SQL database is a bit much for me at the moment - Id have to install and run it from my laptop (getting it installed on a full blown SQL server might be difficult, esp as we are in teh process of getting rid of as many servers as possible).
Passing info from one API call to another seems ok - is it difficult to do?
I have about 47 networks each with anything from 5 to 100 AP devices : / - I have managed to do an API call that returns the serial numbers of every AP device in all networks - so presumably I just need to pass all of these serial numbers to a
/devices/{serial}/wireless/status
?
thanks!
12-06-2022 08:48 AM
yes that is correct, what you could use instead of SQL is a CSV text file to hold the devices you have and with the API call, read the CSV file and pass the device details to the API
so for example if you want to run API on a switch, only pass the device type that is a switch (see example below of a CSV file format)
<device name>,<device serial number>,<device type>,<device network ID>,<device IP Address>
12-06-2022 08:59 AM
so...I have a json (that I could convert to csv) with the following (iv removed some details for posting here);
{
"mac": "mac ",
"serial": "serial number",
"name": "GD - AP - 2",
"model": "MR33",
"networkId": "networkid",
"orderNumber": "ordernumber",
"claimedAt": "2018-07-30T10:30:08.789690Z",
"tags": [ "recently-added" ],
"productType": "wireless"
},
the file contains hundreds of these - I would need to pull out just the serial numbers into (I guess) a query parameter array - not sure how thats done
12-06-2022 12:41 PM
I recommend install Python, version 3.11, then add the Meraki Python library (which handles a lot of low-level stuff for you).
https://www.python.org/downloads/release/python-3110/
https://developer.cisco.com/meraki/api-v1/#!python
It makes working with the API simpler once you get the hang of things.
There are many online sources on learning/using Python. If you get stuck, search with google for what you want to do, i.e. "python array", or "python dictionary" - calls typically return dictionaries, which may have arrays of dictionaries inside them.
Loads of examples here...
https://developer.cisco.com/codeexchange/platforms/meraki#search=meraki&lang=Python
12-06-2022 09:03 AM
yes convert the contents of the json out into a csv file
once you have the data in CSV file, you loop thru the file and pass the serial number as a parameter tto the API call.
12-07-2022 01:28 AM
is that something you have to do in python?
12-07-2022 01:36 AM
you can write code in Python or any other language
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide