cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1812
Views
10
Helpful
2
Replies

DNA API Limit AP Report, is there a better way.

itnetworking
Level 1
Level 1

First let me say thank you, I am a network guy trying to learn Python.

I put together the follow ing code and I am having an issue with the DNA API rate limit. The error and the code is below. What I am trying to do is get a report/CSV that has the AP info and switch port it's connected to. I have a list of 150 IP address to loop over. Once I loop over 5 I get the limit error. Should I be using a different URI to pull the data I need? Am I going about this all wrong?

 

 

ERROR Message 
{'error': "Rate Limit exceeded; BapiName: Get Device Enrichment Details, RateLimit config details: RateLimitContext{rate=5, windowUnit='minute', windowDuration=1, maxConc=5, windowUnit='minute', windowDuration=1, maxConcurrentExecutionsPermitted=0}", 'bapiExtendedStatusCode': 'REJECTED_ABO': 'For BAPI: Get Device Enrichment Details, maximVE_THROTTLE_LIMIT', 'bapiExtendedStatusDescription': 'For BAPI: Get Device Enrichment Details, maximum allowed BAPI instUTC 2020 and now'}ances per 1 minute is 5. The limit has been reached for the time-window between Wed Nov 11 18:44:46 UTC 2020 and now'}
Code

import requests
import http.client
import json
from pprint import pprint
from requests.auth import HTTPBasicAuth
from dnac_config import DNAC, DNAC_PORT, DNAC_USER, DNAC_PASSWORD, DNACU
import csv 
DeviceData = []
a_file = open("aplist.txt""r")
APList = [(line.strip()) for line in a_file]
a_file.close()
fields = ['Switch Name''Port Mode''Swtich Interface''VLAN''AP Address''AP Name''WLC']
url = DNAC + '/dna/system/api/v1/auth/token'       # Endpoint URL
resp = requests.post(url, auth=HTTPBasicAuth(DNAC_USER, DNAC_PASSWORD))  # Make the POST Request
token = resp.json()['Token']    # Retrieve the Token from the returned JSON
#print("Token Retrieved: {}".format(token))  # Print out the Token
with open('GFG.csv''w'as f:   
    write = csv.writer(f) 
    write.writerow(fields)  
for IP in APList:
    conn = http.client.HTTPSConnection(DNACU)
    headers = {
    'X-Auth-Token': token,    
    'entity_type'"ip_address",
    'entity_value': IP }
    conn.request("GET""/dna/intent/api/v1/device-enrichment-details"headers=headers)
    res = conn.getresponse()
    data = res.read()
    device_data = json.loads(data)
    print(device_data)
    for item in device_data:
        DeviceData.append(item['deviceDetails']['neighborTopology'][0]['nodes'][3]['name'])
    for item in device_data:
        DeviceData.append(item["deviceDetails"]['neighborTopology'][0]['nodes'][3]['role'])
    for item in device_data:
        DeviceData.append(item["deviceDetails"]['neighborTopology'][0]['links'][2]['targetInterfaceName'])
    for item in device_data:
        DeviceData.append('VLAN'+item["deviceDetails"]['neighborTopology'][0]['links'][2]['targetPortVLANInfo'])
    for item in device_data:
        DeviceData.append(item["deviceDetails"]['managementIpAddress'])
    for item in device_data:
        DeviceData.append(item["deviceDetails"]['hostname'])
    for item in device_data:
        DeviceData.append(item["deviceDetails"]['associatedWlcIp'])
    with open('GFG.csv''a'newline=''as f:
        write = csv.writer(f) 
        write.writerow(DeviceData) 
    DeviceData = []



1 Accepted Solution

Accepted Solutions

Aninda Chatterjee
Cisco Employee
Cisco Employee

You're using the device enrichment API which is limited to 5 per minute (which is what the BAPI error also tells you). Most of our GET/POST APIs (if not all) should be moving up to 100 per minute (GET) and 50 per minute (POST) with Cyclops (2.1.2.x).

View solution in original post

2 Replies 2

Mike.Cifelli
VIP Alumni
VIP Alumni

Not sure what version of DNAC you are running, but certain APIs have rate-limits (throttling).  Your issue is identified in your DNAC error:

 

{'error': "Rate Limit exceeded; BapiName: Get Device Enrichment Details, RateLimit config details: RateLimitContext{rate=5, windowUnit='minute', windowDuration=1, maxConc=5, windowUnit='minute', windowDuration=1, maxConcurrentExecutionsPermitted=0}", 'bapiExtendedStatusCode': 'REJECTED_ABO': 'For BAPI: Get Device Enrichment Details, maximVE_THROTTLE_LIMIT', 'bapiExtendedStatusDescription': 'For BAPI: Get Device Enrichment Details, maximum allowed BAPI instUTC 2020 and now'}ances per 1 minute is 5. The limit has been reached for the time-window between Wed Nov 11 18:44:46 UTC 2020 and now'}

 

I have had similar throttling issues/concerns.  AFAIK certain APIs are road-mapped to bump rate-limits to 20 requests per minute in later DNAC releases.  If you wish to rely on APIs for your task you would need to implement some sort of timing constraint in your code to delay your loop.  The downside is the time spent figuring that out, and the fact that current API limits would cause your task to take at least 30 minutes (150 IPs/5 per minute).  Your best bet is to mention the concern to Cisco reps, make-a-wish within DNAC admin UI, and keep an eye on later DNAC releases and API updates.  HTH!

Aninda Chatterjee
Cisco Employee
Cisco Employee

You're using the device enrichment API which is limited to 5 per minute (which is what the BAPI error also tells you). Most of our GET/POST APIs (if not all) should be moving up to 100 per minute (GET) and 50 per minute (POST) with Cyclops (2.1.2.x).

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: