Hello Community!
I wanted to start a conversation about best practices for handling pagination in Connect when making Docebo API calls. As many of you know, in order to get all of the information from a large amount of data via API, you have to use pagination. page number and page size dictate this in the search query for your call, but I am curious how you are handling your triggers for increasing pages and loop triggers. Here are some common ones I see.
- Page Number Handling
- Outside of the while loop, create a page number variable starting at 1. Use this variable as the page number inside of your API call. After you complete your operations in your loop, add one to the variable.
- Use the index + 1 of the while loop to set the page number in the API call
- If the recipe logic allows it, use Current Page + 1 of the returned data in the API call as the page number / make a variable starting at 1 and base the next page numbers off of the page number field in the API call
- Somehow creating a for loop based on the total number of pages?
- Something else…?
- Loop break condition
- repeat while page number is less than or equal to the total page count
- repeat while has_more_data
- repeat while returned data[].length > 0
- Something else…?
I have seen these in examples and some differing ones have been instructed to me by folks at Docebo from PS hours. I am curious to hear your thoughts! What are the pros and cons of each to consider, what do you like to do, and what situations require different conditions?
For the page numbers, I personally like to define a variable, as this makes it easier to visualize when I am trying to get details on a call and customize with testing.
In addition, I like to repeat while has_more_data because you don’t risk getting an empty call that you can’t debug at the end of your pagination. In addition, not all calls have extra meta-data at the end (such as the analytics service in the API browser for new reports. However, I have been using data[] > 0 for quite some time. I am also curious on the security of the field vs basing your condition on the actual output of the data.
I would love to hear what you think if you use Connect often or what you do with other API structures beyond Docebo’s format.
Thank you!
Hailey
