Pagination difficulties with v2/catalog - actually it was orders returning variations, not items

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)

Are the missing items from the catalog call deleted items? Does the catalog only have 127 items? I’m not sure I fully understand the question about 99 items in the first response. Are you referring to the limit whether or not a cursor will be present? :slightly_smiling_face:

Hi,
I did a bit more debugging and realized it was skipping all the items I was getting from the ordered items. I was actually searching ITEM_VARIATIONS against ITEMS, which was the issue. Pagination is working fine.
For reference, the orders endpoint reports catalog_object_id meaning it’s a variation, not an item. So you have to treat it as an ITEM_VARIATION to find it :slight_smile:
Cheers for the help!

That’s correct! Glad to hear you figured it out. :slightly_smiling_face: