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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

script running looping URLs and get data

Hi fellow Power BI users,

 

I know Power BI Desktop has 'From Web' feature to get data, but it can only process one URL at a time.  If I have multiple (but similar) URLs, I think a script running looping process is ideal.  Does anyone know how this can be done and processed in Power BI (sample script is preferred)?  Once I have this script, what are the steps to get Power BI process the script? 

 

URLs: - https://inteligence/apps/1/...

https://inteligence/apps/2/..

https://inteligence/apps/3/...

...

with Authorization - bearer <key>

 

Thanks in advance.

1 ACCEPTED SOLUTION

When you add a custom column (Invoke Custom Function), change the drop down to Column Name and select the app_id column.  Then, the function will pass in the app_id value from each row into the function (into the URL) and perform the query steps you designed earlier.  If you need to pass a bearer token to the URL for each app_id value, if it is the same bearer token for every app_id, you can add an Authorization header to the URL request.

 

For example, I have a dashboard that pulls data from Twitter.  Once I obtain the access token (it is the result of a different query named AccessToken) here is the function I use to query Twitter:

 

(params) =>
let
    
    GetJsonQuery = Web.Contents("https://api.twitter.com/1.1/search/tweets.json" & params,
        [
            Headers = [#"Authorization"=AccessToken]
        ]
     ),
    FormatAsJsonQuery = Json.Document(GetJsonQuery),

    data = try FormatAsJsonQuery[statuses] otherwise null,
    next = try FormatAsJsonQuery[search_metadata][next_results] otherwise null,

    res = [Data=data, Next=next]
in
    res

I have a table with a column of search words, where the column name is "keyword".  The parameter named "params" that started off the function above is defined as:

 

params = "?q=" & keyword & "&count=100"

So you can see how the column of hard coded search terms is passed into the url part defined by "params" which is in turn passed into the function.  The function runs on every row in my table of "keyword", so each row returns a table of results, which I can then expand and Power BI will automatically append the results into one table.

 

Note:  This is not the entire query and will not return results (the "data", "next" and "res" variables are used in another query that iterates through pages of results).  Hopefully this shows you how to structure your web call using the bearer token.

View solution in original post

35 REPLIES 35

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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