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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.