Skip to content

Commit 8791aa5

Browse files
- Fixes a KeyError exception when paginating through the API endpoints whose response payloads are JSON objects. (#287)
Co-authored-by: iancart <iancart@cisco.com> Enhances the library by enabling simpler interaction with newer operations that follow the items/meta pattern for pagination.
1 parent bdbfb52 commit 8791aa5

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

meraki/aio/rest_session.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ async def _get_pages_iterator(
388388
# just prepare the list
389389
if type(results) == list:
390390
return_items = results
391+
elif type(results) == dict and "items" in results:
392+
return_items = results["items"]
391393
# For event log endpoint
392394
elif type(results) == dict:
393395
if direction == "next":
@@ -467,6 +469,11 @@ async def _get_pages_legacy(
467469
# Append that page's results, depending on the endpoint
468470
if type(results) == list:
469471
results.extend(await response.json(content_type = None))
472+
elif isinstance(results, dict) and "items" in results:
473+
json_response = await response.json(content_type=None)
474+
results.extend(json_response["items"])
475+
if "meta" in results:
476+
results["meta"]["counts"]["items"]["remaining"] = json_response["meta"]["counts"]["items"]["remaining"]
470477
# For event log endpoint
471478
elif type(results) == dict:
472479
json_response = await response.json(content_type = None)

meraki/rest_session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ def _get_pages_iterator(
377377
# just prepare the list
378378
if type(results) == list:
379379
return_items = results
380+
elif type(results) == dict and "items" in results:
381+
return_items = results["items"]
380382
# For event log endpoint
381383
elif type(results) == dict:
382384
if direction == "next":
@@ -448,6 +450,10 @@ def _get_pages_legacy(self, metadata, url, params=None, total_pages=-1, directio
448450
# Append that page's results, depending on the endpoint
449451
if isinstance(results, list):
450452
results.extend(response.json())
453+
elif isinstance(results, dict) and "items" in results:
454+
results["items"].extend(response.json()["items"])
455+
if "meta" in results:
456+
results["meta"]["counts"]["items"]["remaining"] = response.json()["meta"]["counts"]["items"]["remaining"]
451457
# For event log endpoint
452458
elif isinstance(results, dict):
453459
try:

0 commit comments

Comments
 (0)