cisco-en-programmability/dnacentersdk

Add the ability to depaginate API queries that paginate

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.

My network is quite large, and as such I'm very frequently running queries that return results in excess of the "limit" variable set for the particular function.

As a result, I need to create a loop that re-runs the queries, increasing the offset by the limit (which isn't consistent between functions) until the response is empty, then concatenates the returned lists to give me my full result.

Describe the solution you'd like

Add an option (e.g. "limit=max") that returns all responsive items, regardless of the limit.

Describe alternatives you've considered

This is relatively trivial to workaround on a function by function basis using the method above, but it requires you to have prior knowledge of how the particular function will paginate. It also requires you to know in advance that pagination will be a concern for your particular query, which isn't always obvious.

Let's say that you're using the get_devices API function and currently have 490 switches. You write a bunch of scripts leveraging this API call. Your network then grows, adding a new site, increasing your total to 510. Your script will now only receive the first 500 switches. No exception or warning is raised to alert that this list is incomplete, and your script requires a re-write to handle the new network size.

Hey @pmormr, thanks for the improvement proposal, we will consider it.
On the other hand, we can do workarounds to get all the elements in the apis that paginate, taking the "get_devices_list" endpoint as an example, the workaround would be the following.

max_items= 2 #Here goes API Limit elements per page.
devices =[]
offset= 1
items=max_items
while items >= max_items:
    devices_api = dnac.devices.get_device_list(offset=offset, limit= max_items)
    devices.extend(devices_api.response)
    offset+= max_items
    items= len(devices_api.response)

# Print all of demo devices
for device in devices:
    print('{:20s}{}'.format(device.hostname, device.upTime))

Note:

This workaround may changes in another pagination endpoint.

Regards.

@pmormr
Issue closed due to inactivity