how to enter time query on Wireless usage API

tjh188
Here to help

how to enter time query on Wireless usage API

I know that I can run this Wireless usage API in Python but how do I query the last day or week?

And how do I add the SSID that I want to pull in the print(Response)?

 

The results that I want to see is how many GB per day a particular SSID on an MR network is being used.  I am new to Python but want to learn quickly.

 

dashboard = meraki.DashboardAPI(API_KEY) network_id = 'L_xxxxxxxxxxxxxxxxxxx'

 

 

response = dashboard.wireless.getNetworkWirelessUsageHistory( network_id ) print(response)

 

 

Below is the Full API

https://developer.cisco.com/meraki/api-v1/#!get-network-wireless-usage-history

6 Replies 6
sungod
Head in the Cloud

The usage would be...

 

response = dashboard.wireless.getNetworkWirelessUsageHistory( network_id , t0=starttime, t1=endtime, ssid=netssid)   <<<<edit: this won't work, the call also needs a specific client/device given, see post further down for alternatives

 

Note that the call defaults to a resolution of 86400 seconds (one day), the return is an array of time slices, if you choose a resolution smaller than the time period you request data for, you'll get multiple time slices returned, each for a different part of the overall period.

 

t0 and t1 are strings, giving respectively the start and end of the period you want data for, they can be ISO format timestamps, or simple epoch timestamps (see... https://www.epochconverter.com/ for a way to manually make these), if you want scripts to automatically step through a range of dates, using epoch timestamps can be simpler.

 

If you just want some simple way to get a specific day, such as 31st March you could hardcode them...

 

starttime = "2023-03-31T00:00:00Z"

endtime = "2023-04-01T00:00:00Z"

 

...this is an ISO format datetime with the Z specifying this is UTC, if you're not working in UTC you'd need to adjust things.

 

Doing the same with epoch timestamps would be...

 

starttime = str(1680217200)

endtime = str(1680217200 + 86400)

 

...note that you need to turn the integer into a string for the API call, and to get the end time I simply added 86400 seconds to the start time, much easier than creating the human readable format.

 

If you want to automatically generate timestamps, there're many ways Python can handle datetimes, best way to learn is make some simple script to get familiar, see...   https://docs.python.org/3/library/datetime.html

 

netssid is an integer identifying the SSID

 

To find the SSIDs on a network, use the getNetworkWirelessSsids call...

 

https://developer.cisco.com/meraki/api-v1/#!get-network-wireless-ssids

 

...it returns an array of all your SSIDs.

 

Or you can find the SSID number manually in Dashboard, go to the wireless SSID page, display all SSIDs, the leftmost one is 0, the next is 1, then 2, etc., it's just a simple integer.

 

import os
import meraki
import json

API_KEY = os.environ.get("Meraki_API_KEY")
dashboard = meraki.DashboardAPI(API_KEY, suppress_logging=True)
organization_id = 'xxxxxx'
network_id = 'L_xxxxxxxxxxxxxxxx'
starttime = "2023-03-31T00:00:00Z"
endtime = "2023-04-11T00:00:00Z"

response = dashboard.wireless.getNetworkWirelessUsageHistory(network_id, t0=starttime, t1=endtime,
ssid='3')
 
I don't get anything.  What am I doing wrong?  I get the error on line 12 (the response line).  Everything before that is good.
sungod
Head in the Cloud

You have...  ssid='3'

 

Should be an integer, try...    ssid=3

meraki.exceptions.APIError: wireless, getNetworkWirelessUsageHistory - 400 Bad Request, {'errors': ['Must specify a device or network client']}

 

when I take the ''  off the 3, it gives me the above error.

sungod
Head in the Cloud

Ahh, just noticed in the overview for the API it says "Return AP usage over time for a device or network client", so it's quite a selective call.

 

If you want data for all usage, a different API call would be better, for usage info on SSIDs across all networks, I suggest have a look at...

 

https://developer.cisco.com/meraki/api-v1/#!get-organization-summary-top-ssids-by-usage

 

Call it like...

 

dashboard.organizations.getOrganizationSummaryTopSsidsByUsage(t0=starttime, t1=endtime)

 

Otherwise if you need to be network-specific, look at using this...

 

https://developer.cisco.com/meraki/api-v1/#!get-network-clients

 

t=86400

dashboard.networks.getNetworkClients(netid, timespan=t, perPage=1000, total_pages="all")

 

...it will be more fiddly as you get a lot of data back and it'll be more complex to parse. Basically you need to iterate through return items, choose only those have an 'ssid' parameter present, then check if that ssid is the one you are interested in, if it is you look at the 'usage' element and add the sent and recv bytes to a running total.

 

Also, the call only allows specifying either a t0/start time (but NOT a t1/end time), or a 'timespan' which is the number of seconds to look back before 'now', I call it every 24 hours to get the previous 86400 seconds of data.

I really need to find the answer to my original question.  Different API calls will not accomplish what I am wanting.  I need the total GB or MB from a week's time flowing only from one SSID.  I don't need to drill down to a client to get client data.  

 

I don't need the top devices.  I need all devices.

Get notified when there are additional replies to this discussion.