07-26-2022 04:58 PM
Hello,
When using the following API string it seems that I do receive only the first five hundred devices.
Solved! Go to Solution.
07-27-2022 03:38 PM
Thank you for all your precious input. In the meantime, I was able to find the solution by referring to: "offset = 500"
https://community.cisco.com/t5/cisco-digital-network/dna-center-api-500-record-limit/td-p/4125116
07-27-2022 03:38 PM
Thank you for all your precious input. In the meantime, I was able to find the solution by referring to: "offset = 500"
https://community.cisco.com/t5/cisco-digital-network/dna-center-api-500-record-limit/td-p/4125116
07-06-2023 05:12 AM
Unfortunately, as per the API documentation for DNA, there is no pagination mechanism provided, requiring manual incrementation of the offset parameter. Due to the link endpoint should look like: /dna/intent/api/v1/network-device/{startIndex}/{recordsToReturn}, where we need to increment startIndex param which also cannot be 0 and should start from 1
def get_dnac_devices(server_ip, username, password):
# Authenticate and obtain the token
response = requests.post(f"https://{server_ip}/dna/system/api/v1/auth/token",
auth=(username, password), verify=False)
print(response.url)
try:
all_devices = []
token = response.json()['Token']
print(f"token: {token}")
headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
url = f"https://{server_ip}/dna/intent/api/v1/network-device"
start_index = 1
records_to_return = 500
while True:
# Construct the URL with the current pagination parameters
current_url = f"{url}/{start_index}/{records_to_return}"
# Send the request
print(current_url)
dev_response = requests.get(current_url, headers=headers, verify=False)
response_json = dev_response.json()
devices = response_json.get('response', [])
#print(devices)
# If no devices are returned, break out of the loop
if len(devices) == 0:
break
# Add the devices from the current page to the list
all_devices.extend(devices)
# Increment the start index for the next page
start_index += records_to_return
print(f"incrementing index: {start_index}")
return all_devices
except Exception as e:
error = f'error occured: {e}'
print(error)
return error
get_dnac_devices('server_ip', 'username', 'password') # specify you server IP and credentials here
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