There is a simpler way to query API with pagination. An updated (and simplified) example is published in a new thread: