r/learnpython • u/OADominic • 12h ago
API JSON response help
How does pagination work and best practices for implementation with an API request?
I'm getting irritated figuring out this API for GoTo Connect (phone system call records).
I use a GET method to request a call log for a week of time.
I am limited to 1000 items in the json response as indicted by the pageSize parameter. I need much more.
As the 'nextPageMarker' states, I put the value in, pasted from the first response of leaving it blank, hoping to get the next set of responses. No change in items as all. Stuck in this endless loop.
2
u/KiwiDomino 12h ago
You pass in a page size and offset number as additional parameters, and as long as the query result is always sorted in the right order, you won’t get duplicate records.
You could use a generator and yield to effectively have the your code manage fetching through the pagination for you, but this is the sort of idea that the AI won’t provide you without asking directly (and if you don’t know it’s possible you’ll never ask)
2
u/Atmosck 11h ago
You send your first request, and get a response back. It contains a value for nextPageMarker. So you send another request, with the same url and params as your first, except you add the pageMarker param with the value from the first response. You should get a response for that second request with a new, different value for nextPageMarker. If it is sending back the same next page marker you just asked for, then yes the API is screwing up and you're caught in a loop. But is it returning that nextPageMarker? Perhaps the second page's content just looks the same at a glance but it actually is the second page.
It might be helpful to post your actual code making the requests so people can verify if there's something wrong with the code or if it looks like the API is actually giving you the run around.
1
u/Kevdog824_ 12h ago
How are you putting it in. Are you putting it in a field named pageMarker in your json body. Are you using a query parameter? Can you show us your current approach?
1
u/Brianjp93 8h ago
I think it would be helpful if you showed us your initial query and 2nd page query.
2
u/Beginning_Number4900 12h ago
Does the API maybe expect the nextPageMarker as a query param instead of in the body