Can we use Bulk Get to return wireless health status by using api?

liu
Meraki Employee
Meraki Employee

Can we use Bulk Get to return wireless health status by using api?

We got the error 429 if we use a circle command to get all the wireless health status for all the networks. We have over 100 networks in an Org. We know the limit rate is 5 calls per second per Org.  

 

Can we use one Get request to return the wireless health status of multi-networks? For example: GET/networks/{networkId}/failedConnections.

 

 

 

6 REPLIES 6
BrechtSchamp
Kind of a big deal

Don't think there is any way at the moment. Action batches don't support the resource you need at the moment:

https://developer.cisco.com/meraki/api/#/rest/guides/action-batches/

 

I guess you'll have to insert a sleep rule in your script to avoid hitting the 5 calls per second limit.

 

E.g. in python:

import time

time.sleep(5)

Hi BrechtSchamp, 

 

Thank you for your reply. It looks like we have to use the sleep rule:)

Nash
Kind of a big deal

There's also the Meraki github repo's sleep method. I use this all the time. I've included a sample request so you can see how the whole shebang works...

 

 

import time
import requests
from datetime import datetime

# Used for time.sleep(API_EXEC_DELAY). Delay added to avoid hitting
# dashboard API max request rate
API_EXEC_DELAY = 0.21

# connect and read timeouts for the Requests module
REQUESTS_CONNECT_TIMEOUT = 30
REQUESTS_READ_TIMEOUT = 30

# used by merakirequestthrottler(). DO NOT MODIFY
LAST_MERAKI_REQUEST = datetime.now()

def merakirequestthrottler(p_requestcount=1):
    """Add delay to requests to avoid hitting shaper."""
    global LAST_MERAKI_REQUEST

    if (datetime.now() - LAST_MERAKI_REQUEST).total_seconds() < (API_EXEC_DELAY * p_requestcount):
        time.sleep(API_EXEC_DELAY * p_requestcount)

    LAST_MERAKI_REQUEST = datetime.now()
    return

def printusertext(p_message):
    """Print a line of text meant for the user to read.

    Do not process these lines when chaining scripts
    """
    print(f'@ {p_message}')

def getnetworklist(p_apikey, p_orgid, p_shardurl):
    """Return list of networks for specified organization."""
    merakirequestthrottler()
    r = ""
    try:
        r = requests.get(f"https://{p_shardurl}/api/v0/organizations/{p_orgid}/networks", headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT))
    except:
        printusertext('ERROR 02: Unable to contact Meraki cloud')
        sys.exit(2)

    rjson = r.json()

    return(rjson)

 

 

liu
Meraki Employee
Meraki Employee

Hi Nash, 

 

Great sample. Thank you very much!

PhilipDAth
Kind of a big deal
Kind of a big deal

I gave you a kudo because it's impressive you manage to hit the 5 API ratelimit using Python (assuming you are using Python).

 

@Nash has an excellent solution.

 

Is there any chance you can move more of the processing of the results (assuming you are doing further processing) to being right after you make the call to collect the results?  That might introduce enough of a delay that it isn't an issue anymore.

Nash
Kind of a big deal

I use @PhilipDAth's processing trick quite a bit too. Make a call, crunch the data as I can, make more calls.

 

Also helps that I'm working across dozens of organizations with a handful of networks each. Pretty glad the rate limit is per-organization.

Get notified when there are additional replies to this discussion.