Get NFTs by contract seems to be able to paginate PAST the max NFTs issued

Hi
I wanted to pull some data for analysis, so I wrote some python code to loop through the " Get NFTs by contract" endpoint. As long as the endpoint returns a cursor, it loops and re-runs with that cursor to get the next page of results (up to a max number of runs I set).

A test NFT contract I tried with, has 5000 NFTs. Mistakenly I asked it to loop over 100 times, as I assumed I’d need to pull data on 10k NFTs (the extra 5 runs over 100 just to be sure).
To my surprise it printed 10,500 results.
I then discovered the last 5,500 (over the 5000 existing NFTs) was just the last page of results over and over again.

What is the expected behaviour after reaching the end of all existing NFTs in the contract? Surely it should not return a cursor as there would be no next page of results?
But then I seem to recall seeing you guys turned off the ability to get total max number of NFTs by contract, at some point? Is this why the endpoint would seem to continue forever (if we didn’t limit it to X number of runs manually?)

Thanks
Jimmy

Hi @JimBob

You should rely on the cursor value to create a looped requests rather than using a fixed number of loops. On the last page you will see the cursor value as null.

You can find an example pagination code on the below page.

Thanks @johnversus, that’s what I did. The loop uses a combination of returned cursor value, AND a max number of runs, as a safety. And lucky I did, because otherwise it would have kept going forever.

As a test, I printed out cursor value each iteration of the loop. Once it got past the total number of NFTs, it printed “None”. Should it not have printed “” ie, nothing, if there is no cursor returned?
I changed the code to detect both “” and None, and now my code works.
But
To me this seems “wrong”, but maybe I’m not understanding something. Maybe printing None is what python does when it has a null value. To me I would have expected it to print a blank, not the word “None”. As I said, perhaps my understanding is faulty, but I would like to hear from you what you intend the cursor to return - “None” or simply nothing.
Thanks!

Ah and I see that’s what your python example does too, check for “” and also not None.
I don’t know, to me that seems redundant but this may be my faulty knowledge tricking my own brain.

Ahh ok ok. Have you testing with logic from docs?