Forum Discussion
Paginated List Query Error
- 1 year ago
Hi Mobleyjk
Thank you for reaching out to the Microsoft Fabric Community Forum.
The error happens because the API response doesn't always include the 'next' field. When you get to the last page of the API pagination, the 'next' link can be null or missing. The current M code tries to access the 'next' field without checking if it exists, which leads to this error: Expression.Error: The field 'next' of the record wasn't found.
Please try the below M Code :let InitialUrl = "link.link", GetPage = (url as text) as record => let Response = Json.Document(Web.Contents(url)), NextLink = if Record.HasFields(Response, "next") then Response[next] else null, ResultData = Response in [Result=ResultData, Next=NextLink], Pages = List.Generate( ()=> GetPage(InitialUrl), each [Next] <> null, each GetPage([Next]), each [Result] ), #"Converted to Table" = Table.FromList(Pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error) in #"Converted to Table"
I hope this information is helpful. If you have any further questions, please let us know. If this does not helps please share more details so we can assist you further.
Regards,
Karpurapu D,
Microsoft Fabric Community Support Team.
Hi Mobleyjk
We have not yet heard back from you about whether our response addressed your query. If it did not, please share more details so we can assist you more effectively.
Thank You.