Forum Discussion
Can't refresh dynamic API URL in Power BI service
Hi
I have a paginated API data source in a Power BI report, that used the following M code to iterate through and combine multiple pages into a single table, but I then can't refresh the report or schedule a refresh for the report in the Power BI service, because it's a dynamic data source.
let
// Base URL and parameters
BaseUrl = "[URL]",
ApiToken = "[API Token]",
Limit = 500,
InitialStart = 0,
// Function to fetch one page of results
GetPage = (Start as number) =>
if Start = null then
[Data = {}, More = false, NextStart = null]
else
let
Url = BaseUrl & "start=" & Text.From(Start) & "&limit=" & Text.From(Limit) & "&api_token=" & ApiToken,
Response = Json.Document(Web.Contents(Url)),
Data = Response[data],
More = try Response[additional_data][pagination][more_items_in_collection] = true otherwise false,
NextStart = try Response[additional_data][pagination][next_start] otherwise null
in
[Data = Data, More = More, NextStart = NextStart],
// Loop through all pages using List.Generate
AllPages = List.Generate(
() => [Result = GetPage(InitialStart), Continue = true],
each [Continue],
each [
Result = GetPage([Result][NextStart]),
Continue = [Result][More]
],
each [Result][Data]
),
// Flatten all results into one list
Combined = List.Combine(AllPages),
// Convert to table, automatically detecting columns
RawTable = Table.FromRecords(Combined),
in
RawTable
Has nayone come acros this before and can you tell me how to resolve it, I'm currently opening the report in Power BI desktop each morning to refresh it and then re-publishing the refreshed report to the service, but this isn't a sustainable solution
I've seen a video where they changed the dynamic URL to a Static URL, using [RelativePath = BaseURL & ""], but I couldn't get that to work for me, I'm guessing because mine is wrapped in a function?
I've also read about using a call into the API to trigger a refresh with a RefreshData endpoint, but the API I'm using doesn't have this endpoint
I can't belive I can build a report in Power BI Desktop with a data souce that i can refresh from there, but that I can't refresh from the Power BI service, there must be a solution
Any help would really be appreciated. I can't keep manually refreshing for ever more
Cheers
Jim