Forum Discussion
Pagination code returns first page forever instead of properly paginating
- 3 years ago
Thanks ams1 -
I'm not able to share the API documentation directly, but here's a sample response object they provided:{ "responses": [ { "id": "5e22085d5379215be800002b", "survey_id": "6e22085d5379215be800002b", "created_at": "2020-09-24T00:20:10", "conversation_id": "7e22085d5379215be800002b", "answers": [ { "question": { "id": "5e22085d5379215be800002b", "value": "Choose one option", "type": "multichoice | multiselect | range | nps | singleline" }, "answer": { "value": "'yes' OR ['Red', 'Blue']" } } ], "snapshot_data": { "device": { "id": "55fbe2e775bf3c760b1000bc", "carrier": "Verizon", "custom_data": { "key": "CustomKey", "value": "CustomValue" }, "manufacturer": "Samsung", "model": "S22", "os_api_level": "3.5.9", "os_name": "Android", "os_version": "5.2.0" }, "person": { "id": "95fbe2e775bf3c760b1000bc", "custom_data": { "key": "CustomKey", "value": "CustomValue" }, "email": "[email protected]", "facebook_id": "1184928249824", "mparticle_id": "-29482958295729572", "name": "Jack Daniels" }, "app_release": { "cf_bundle_version": "78", "cf_bundle_short_version_string": "4.5.11", "sdk_version": "4.5.11", "sdk_platform": "iOS", "sdk_distribution": "source", "sdk_distribution_version": "4.5.11" } } } ], "ends_with": "6e22085d5379215be800002b", "page_size": 250, "has_more": true }And these are the sample params:
I've tried your sample code and I think I just need to make sure the result is the `"responses": [` portion and the `ends_with`, `page_size`, and `has_more` just used for cursor/paging.
Exactly - you just need to extract "responses" from "pages" - you should be able to do that using the 4th parameter of List.Generate (the selector).
Don't forget to mark as ANSWER the reply if it helped.
ams1 Awesome! Syntax-wise, what would that fourth parameter look like?
- pages[responses]
- getNextPage[responses]
- lastPage[responses]
- None of the above, silly
?
- ams13 years agoResponsive Resident
Hi,
Somehow I've missed your reply - sorry for that.
If you haven't figured it out (but I think you did), it can be something like:
... pages = List.Generate( // initial () => getNextPage(null), // condition (lastPage) => lastPage <> null, //next (lastPage) => getNextPage(lastPage), // selector (lastPage) => lastPage[responses] // <--------- ) ...Thanks for the "thumbs-up" (aka kudo), but please also mark as ANSWER the most relevant replies -> so that the question status is answered. 😊
- mrsalta3 years agoNew Member
I did! Thank you for the last answer, too.