Forum Discussion
gotmike
10 years agoFrequent Visitor
how to create a query that paginates?
I'm working with the Hubspot CRM API and when you query for a list of all deals, you only get 100 records at a time, and they want you to send subsequent queries with an "offset" to paginate the resu...
ImkeF
Community Champion
9 years agoHi Peter,
This is a "real" pagination and I think List.Generate is best to handle this. The code would probably be look like so:
let Pagination = List.Generate( () => [Last_Key = "20170319015902380428278"], // Start Value each [Last_Key] <> null and [Last_Key] <> "", // Condition under which the next execution will happen each [Result = "https://url.com/?fromday=20170301&today=20171231&offset="&[Last_Key]&"%4041627&authKey=123", // retrieve results per call Last_Key = Result[lastKey] ], // determine the LastKey for the next execution each [Result]) // Select just the Result-record in Pagination
It might need a bit of tweaking because I couldn't test it, but the general principle is this:
1) pass the necessary parameters into the first argument of the function (here: Start value for LastKey
2) define the condition under which the execution of the next step shall happen
3) define the record which contains the step(s) to execute
4) optional argument which lets you select specific record-fields: In this case we're just interested in the "Result" and not the LastKeys used
kroll
9 years agoFrequent Visitor
Imke, thank you for the quick response. It's super helpful.
I'll give it a try later today.