nextPageToken

Has anyone figure out a way to handle nextpagetoken from an api call in Wappler. I am still trying to figure out the best way to loop through YouTube nextpagetoken to get all the rows retuned from the api call? YouTube only gives you 50 rows max and you have to use the nextPageToken to loop through the records. Thanks

@Teodor or anyone!

Can you show me what the next page looks like, like the raw data.

Sure hold one sec while I get it.

Does this work? if not I can pull up the file this is an pic that I last posted
image

I have not done this with YouTube specifically but I have with many others, so assuming it works in a similar way.

Your API result when more records are available should have an additional record in the response, with a URL taking you to the next page or the previous page.

On your server action start off with a SetValue step with the initial URL for the call.
Example:
2022-02-10_22-40-23

Please note the use of Name, and Global Name

Next add a While Loop with a Condition of the SetValue Step, which will always be true until we tell it to reset the value.

Now add your API action inside the loop
Example:

As you can see the Url is getting its path from the SetValue step, if the raw result of the query is 5 records then it will have no “nextRecordsUrl”, and if it returns 22 results then it will have a url inside the raw result.

Directly after the API call add another SetValue step, which will update the value of the global SetValue step outside the loop, if no url is returned then the while loop is false and stops, meaning you have reached the end of the result, if it does have a url then it will keep looping till all the results are fetched.
Example:
2022-02-10_22-49-18

Please note the Name, and the Global Name which is exactly the same Global Name as the first SetValue step, therefore overwriting the initial Global Var.

Your end result server action will look something like this.

Obviously this is just a concept of how i use it to return all results even if there is a million and the API has a limitation of only showing 2000 per page, so i can populate my own database with the results, but adjust as you need.

@psweb You are a Rock Star from the Mother Land my friend, and why didn’t I think of putting all the next pagetoken url in a set value! It’s because @psweb is a genius and I am not. Thanks a lot I am going to try this implement right now and let you know how it turns out.