I’m struggling with the pagination logic using the Python SDK with the catalog endpoint, retrieving all my items. It seems that I get 127 items, but when I’m matching that data against what I get from the orders endpoint, there are missing ITEMs, suggesting I’m not getting everything.
In the below, you’l notice the weird ‘current_cursor=True.’ That’s not in the recommended pattern, but I was struggling to understand how that pattern deals with <100 results. If you get 99 ITEMs in your first response, then you never enter the while loop, so you must repeat the code inside and outside the while loop. It seemed more efficient to only write the code once, and just force it into the while loop from the get go.
Here is the relevant code:
items = {}
current_cursor = True
result = client.catalog.list_catalog(
types = "ITEM",
)
if result.is_success():
while current_cursor:
for i in result.body['objects']:
items[i['id']] = i
current_cursor = result.cursor
result = client.catalog.list_catalog(
types="ITEM",
cursor=current_cursor,
)
current_cursor = result.cursor
if result.is_success() and not result.cursor:
for i in result.body['objects']:
items[i['id']] = i
elif result.is_error():
print(result.errors)