Forum Discussion
Recursive API Get request from Dynamics BC
- Anonymous11 months ago
Hi visheshvats1 ,
Thank you for reaching out to the Microsoft fabric community forum.
The issue you're experiencing isn't with accessing @odata.nextLink itself, but rather with how the recursive loop is set up in your List.Generate function. Currently, your code retrieves only the first page and doesn't continue through all the remaining pages.
As vojtechsima mentioned, it's important to "lag one request behind" so that each iteration checks for @odata.nextLink before proceeding. This approach ensures you reach the final page and avoid stopping prematurely. While their example was for the Power BI Admin API, the same principle applies to Dynamics BC.
Below is a Power Query pattern that you can use for your Dynamics BC endpoint:
let GetPage = (url as text) => let Response = Json.Document(Web.Contents(url, [Headers=[Authorization="Bearer " & AccessToken]])), Data = if Record.HasFields(Response, "value") then Response[value] else {}, NextLink = if Record.HasFields(Response, "@odata.nextLink") then Response[@odata.nextLink] else null in [Data = Data, NextLink = NextLink], Source = List.Generate( ()=> GetPage(BaseUrl), each [NextLink] <> null, each GetPage([NextLink]), each [Data] ), Output = Table.FromList(List.Combine(Source), Splitter.SplitByNothing(), null, null, ExtraValues.Error) in OutputHope this helps, Please feel free to reach any further assistance.
Thank you.
Hi visheshvats1 ,
Thank you for reaching out to the Microsoft fabric community forum.
The issue you're experiencing isn't with accessing @odata.nextLink itself, but rather with how the recursive loop is set up in your List.Generate function. Currently, your code retrieves only the first page and doesn't continue through all the remaining pages.
As vojtechsima mentioned, it's important to "lag one request behind" so that each iteration checks for @odata.nextLink before proceeding. This approach ensures you reach the final page and avoid stopping prematurely. While their example was for the Power BI Admin API, the same principle applies to Dynamics BC.
Below is a Power Query pattern that you can use for your Dynamics BC endpoint:
let
GetPage = (url as text) =>
let
Response = Json.Document(Web.Contents(url, [Headers=[Authorization="Bearer " & AccessToken]])),
Data = if Record.HasFields(Response, "value") then Response[value] else {},
NextLink = if Record.HasFields(Response, "@odata.nextLink") then Response[@odata.nextLink] else null
in
[Data = Data, NextLink = NextLink],
Source = List.Generate(
()=> GetPage(BaseUrl),
each [NextLink] <> null,
each GetPage([NextLink]),
each [Data]
),
Output = Table.FromList(List.Combine(Source), Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
Output
Hope this helps, Please feel free to reach any further assistance.
Thank you.
Thanks for the response, but i'm getting a syntax error.
- vojtechsima11 months agoSuper User
visheshvats1 as @ it's special charcater, use the specific notation:
[#"@odata.nextLink"]