Forum Discussion

Arnoh's avatar
Arnoh
Helper III
1 year ago
Solved

Power BI Service not sending Basic Authentication with Web.Contents using RelativePath

Hi everyone,

I have a dataset in Power BI Desktop that uses the following M code to retrieve paginated data from the API. It works perfectly in Desktop — all pages are fetched using Web.Contents with RelativePath and Query parameters.

 

let

    BaseUrl = "https://app.xxxxx.com   ",

    Endpoint = "api/v2/employees",

 

    GetPage = (PageNumber as number) =>

    let

        Source = Json.Document(Web.Contents(BaseUrl, [

            RelativePath = Endpoint,

            Query = [

                page = Number.ToText(PageNumber),

                size = "100"

            ]

        ])),

        Bron = Source[items],

        Data = Table.FromRecords(Bron)

    in

        Data,

 

    FirstPage = Json.Document(Web.Contents(BaseUrl, [

        RelativePath = Endpoint,

        Query = [

            page = "0",

            size = "100"

        ]

    ])),

    TotalPages = FirstPage[totalPages],

    PageNumbers = List.Numbers(0, TotalPages),

    CombinedData = Table.Combine(List.Transform(PageNumbers, each GetPage(_)))

in

    CombinedData 

 

 

This setup works flawlessly in Power BI Desktop. However, once I publish the dataset to the Power BI Service and try to refresh it, I get the following error:

 

The credentials provided for the Web source are invalid. (Source at  https://app.xxxxx.com/api/v2/employees  .) 

In the Power BI Service, the credentials are correctly configured as Basic Authentication for  https://app.xxxxx.com/  , and the data source appears correctly under dataset settings. Yet it seems that the credentials are not being sent with the actual API calls in the Service.

 

What I’ve tried: 

    • Confimed that credentials are correctly set for in the power bi service for 

 

My suspicion: 

Power BI Service does not send Basic Authentication headers when using Web.Contents with RelativePath and Query, even when credentials are set at the root domain level.

 

My questions:

  • Is this a known limitation in Power BI Service?
  • Are there any best practices to make Basic Authentication work with RelativePath?

 

Any help or confirmation of this behavior would be greatly appreciated.

Thanks in advance!

  • Hi Arnoh ,
    Great to hear you identified the root cause! When visuals show “Visual has pending changes” and require manual refreshing after a dataset update, it’s often due to the "Pause visuals" setting under the Optimization pane being enabled. This feature is helpful when working with large models or making several changes, as it temporarily suspends visual updates for performance, but can be confusing if toggled unintentionally. If anyone else encounters this issue, simply go to the “Optimize” ribbon in Power BI Desktop and uncheck “Pause visuals.” Once deselected, your visuals will resume auto-refreshing as expected after dataset updates. Also, keeping Power BI Desktop updated and clearing the cache occasionally can help avoid unexpected behavior.

     

  • Hi it seems to be an issue in the power bi service. But there is a workaround you can make a connection inside the power bi service instead of entering the credintials in the workspace. 

9 Replies

  • Hi Arnoh It might be because Power BI Service doesn’t send Basic Authentication headers with RelativePath. Combine the full URL in Web.Contents, or include the Authorization header with Base64-encoded credentials. Another thing you could try is setting credentials for the exact API endpoint instead of the root domain. I think this is a known limitation, so avoid RelativePath and use full URLs or custom headers for consistency.

    • Elipum's avatar
      Elipum
      Regular Visitor

      Hi, I did set up credentials for the url that requires authentication (multiple api keys for url that share the root, and powerbi only recognises the root at gateway and not the different ones). I created an anchor query mentioning every single url with full path to endpoints. Set all credentials at source settings in desktop. Still, Service doesn't seem to recognize them. Any other approach to test?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Arnoh 

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

    Thank you.

  • Hi Arnoh ,
    Great to hear you identified the root cause! When visuals show “Visual has pending changes” and require manual refreshing after a dataset update, it’s often due to the "Pause visuals" setting under the Optimization pane being enabled. This feature is helpful when working with large models or making several changes, as it temporarily suspends visual updates for performance, but can be confusing if toggled unintentionally. If anyone else encounters this issue, simply go to the “Optimize” ribbon in Power BI Desktop and uncheck “Pause visuals.” Once deselected, your visuals will resume auto-refreshing as expected after dataset updates. Also, keeping Power BI Desktop updated and clearing the cache occasionally can help avoid unexpected behavior.

     

    • jimbob2285's avatar
      jimbob2285
      Advocate IV

      Hi All

       

      I've encountered the very same problem

      • And the solution for me, which florianh suggested in this thread: Failed to update data source credentials
      • Was to tick "Skip Test Connection" when editing the Data Source Credentials
      • I'm guessing that because of the way the URL is constructed in the M code, to bring back and combine all the paginated pages
      • That the Power BI Service only supplies the base URL when testing the connection
      • Which will obviously fail, as it doesn't contain the API Key
      • So, I presume skipping the test connection lest you set up the credentials
      • Which then work correctly when refreshing the data set, as the full url, with the API Key, is passed to the API

      Can any of the experts on here clarify that this is the accepted solution to this problem?

       

      Also, why is there a response in this thread about Paused Visuals, where did that come from, as it seems to have nothing to do with the original question?

       

      I've also added my M code below, if that helps anyone else reading this thread - Credit to v-ssriganeshBA_Pete and v-dineshya for helping to adapt my original code in to a working solution

       

      Cheers

      Jim

       

      let
          // Base URL and parameters
          BaseUrl = "https://api.XXXXX.com",
          ApiToken = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
          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)),
                      Response = Json.Document(
                          Web.Contents(
                              BaseUrl, [
                                  RelativePath =  "/v1/organizations?",
                                  Query = [
                                          start = Text.From(Start),
                                          limit = Text.From(Limit),
                                          api_token = ApiToken
                                  ]
                              ]
                          )
                      ),
                      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

       

    • Elipum's avatar
      Elipum
      Regular Visitor

      Has any body found a working solution yet?

      I am having a similar issue.

      In my case, apikey authentication needs to be passed at

      https://app.xxxxx.com/api/company1 

      Or https://app.xxxxx.com/api/company2 

      Because I have to combine data from multiple sources that require different API keys.

       

      I overcome the dynamic URL issue that prevented refresh by using webcontents instead of Baseurl, and the relative path approach.

      My dataset contains many many endpoints. Fx. https://app.xxxxx.com/api/company1/employees 

      Per each of the companies I am joining in the model. 

      I started getting the error of missing credentials at root, so I set it as Anonimous. 

      Now I am getting the error of missing credentials at end point, so I created a query to use as anchor mentioning every single url I use in the model. Not ideal because I need to remember to add new endpoints if I ever need one extra, and they are already a lot!

      I then defined credentials in Source settings in desktop for each of this endpoints, which now appear in the sources list (they inherited password from the sources I already had for https://app.xxxxx.com/api/company1 anyways 

      Well ... it is not working.... it still claims credentials are missing for each endpoint url. I already set the root test to skip, which is the only url recognised at Gateway.

      Any other ideas?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Arnoh 
    I wanted to check if you had the opportunity to review the information provided  by Akash_Varuna  and rohit1991 . Please feel free to contact us if you have any further questions. If their response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
    Thank you.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Arnoh 
    I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
    Thank you.

  • Arnoh's avatar
    Arnoh
    Helper III

    Hi it seems to be an issue in the power bi service. But there is a workaround you can make a connection inside the power bi service instead of entering the credintials in the workspace.