Skip to main content

Pagination on the API returns different results in production vs. testing environments

It seems that the API returns different responses in my testing and the production environments, specifically for the case of the survey_responses endpoint. I don't get the pagination variables in the production environment, and, as a result, my code breaks. 
In my app, I need the pagination information in order to loop through the all of the survey responses for a client and gather all the relevant responses based on user ID. It's a major part of the app as they're expecting a lot of responses and pagination will eventually become an issue, so I need more than the max 1000 that is set by the API.
So, part of my method asks: 
client.call(:survey_responses, :index, survey_id: 47, per_page: 1000)

When I run this method locally, I get the pagination information up at the top (page, total_pages, per_page, total); the same result as in NB's API Explorer. When I run it in my production environment... Heroku, nada.

The interesting thing is that the "next" and "prev" hash show up both locally and in production. So, I also tried to use them as markers to loop, making API calls until the "next" hash returns nil, spelling the end of the pagination. Again, this works perfectly fine locally. However, in production this actually made it worse because it resulted in an infinite loop which crashed the app. It seems the API never actually returns next as "nil", but instead keeps returning a unique API URL to the "next" set: "/api/v1/survey_responses?__nonce=[omitted]&__token=[omitted]&page=1448&per_page=100&survey_id=47"

I'm trying to figure if it's NationBuilder's API, my app or Heroku that are causing this discrepancy. Am reaching out to Heroku as well and testing the app itself.

I wanted to see if anyone else has come across this and solved it?

Share this post

Showing 5 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.