Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
LaneLourcey
Frequent Visitor

How to convert Dynamic Web.Contents Query for Gateway Refresh

As it says in the title, I'm trying to pull a large dataset via an API and after getting the query working I can't figure out why it's still reading as dynamic after using RelativePath & Options. This takes almost 40 mintues to refresh so I'm hoping someone can help me out with the query and explain what it happening for this to be read as dynamic.

 

I have the main Query that pulls a list of IDs from the system, and then a function that gets called on that list of IDs to pull records related to that ID from the same API

 

 

let
    BaseUrl = "https://api.site.com/odata/v2/User?$filter=location eq 'company'&$select=userId&$format=json",
    Token = "TOKEN",
    Options = [Headers=[ #"Authorization" = "Basic " & Token ]],
    MyJsonRecord = Json.Document(Web.Contents(BaseUrl, Options)),
        
    Result = MyJsonRecord,
    d = Result[d],
    Count = Record.FieldCount(d),
    FirstNextUrl = try d[__next] otherwise null,
    
    GetNextData = (Url) as record => 
        let
            NextRecord = Json.Document(Web.Contents(Url, Options)),
            d = try NextRecord[d] otherwise null,
            data = [ results = try d[results] otherwise null,
                     __next = try d[__next] otherwise null,
                     count = try Record.FieldCount(d) otherwise 0 ]
        in
            data,   

    FullList = List.Generate( () =>
        [ i = 2000, NextUrl = GetNextData(BaseUrl)],
        each [i] <> 0,
        each [i = [NextUrl][count] , NextUrl = GetNextData([NextUrl][__next])],
        each [NextUrl]  ),
    #"Converted to Table" = Table.FromList(FullList, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    ..., // Expanding Columns and such here...
    #"Expanded Column1.results1" = Table.ExpandRecordColumn(#"Expanded Column1.results", "Column1.results", {"userId"}, {"Column1.results.userId"}),

    #"Invoked Custom Function" = Table.AddColumn(#"Expanded Column1.results1", "Learning Hours", each GetLearningHours([Column1.results.userId])),

 

 

The customer function called here is as follows

 

(user) =>
let
    Token = "TOKEN=",
    content1= "{
	""grant_type"":""client_credentials"", 
	""scope"":{ 
		""userId"":""USERID"", 
		""companyId"":""COMPANYID"", 
		""userType"":""admin"",
		""resourceType"":""some_api""
		}
    }",
    Options = [Headers=[ #"Authorization" = "Basic " & Token ], Content = Text.ToBinary(content1)],
    BaseUrl = "https://comp.site.com/path/oauth-api/rest/v1/token",
    Source = Json.Document(Web.Contents(BaseUrl, Options)),
    Result = Source,
    tk = Result[access_token],
    userf = "'" & user & "'",
    Options2 = [Headers=[ #"Authorization" = "Bearer " & tk ], RelativePath="path/odatav4/public/user/user-service/v1/historys?$filter=criteria/targetUserID eq " & (userf)],
    BaseUrl2 = "https://comp.site.com/",
    Source2 = Json.Document(Web.Contents(BaseUrl2, Options2))
in
    Source2

 

I'm really flailing around at this point, so any insight or direction here would be helpful. It isn't clear to me what is dynamicly generated at this point that isn't captured in relative path.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Two suggestions -

1. I would get your token once in a separate query and then use it your two functions to save getting is many times (potentially)

2. Consider a different approach to get lots of data through multiple web calls.  Please see if this helps (not sure, just FYI just in case).  

Power BI - Tales From The Front - REST APIs - YouTube

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

1 REPLY 1
mahoneypat
Microsoft Employee
Microsoft Employee

Two suggestions -

1. I would get your token once in a separate query and then use it your two functions to save getting is many times (potentially)

2. Consider a different approach to get lots of data through multiple web calls.  Please see if this helps (not sure, just FYI just in case).  

Power BI - Tales From The Front - REST APIs - YouTube

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.