Forum Discussion

kramaswamy7's avatar
kramaswamy7
Regular Visitor
4 years ago

Struggling to understand authentication with Web.Contents

Hi all,

 

I've seen a ton of threads explaining how to properly configure Web.Contents to work with Power BI Online - but all those threads refer to authentication that occurs within the header, or with a querystring.

 

My particular requirement is to configure Web.Contents to work with Power BI Online, but using authentication parameters stored in the body. In particular, see at the end of this post for my current code (which works in Power BI Desktop). A few things to note:

 

  1. I have seen some posts mentioning that relative paths can cause problems. I do have a relative path, and, if necessary, I can change the call to pass that as part of the Web.Contents call.
  2. User name, password, and API key are all going to be static, and can be stored anywhere - ideally, though, they would *not* be stored here. I'd much prefer the ability to store them in the credential manager, but I can't seem to find a way to do that.
  3. Even with the previous two addressed - I still can't understand how to make this publishable into Power BI Online. Do I need to use a gateway or a custom connector for this to work properly?
let
    url = "https://my.nonexistent.website/my/relative-path",
    username = "UserName",
    password = "Password",
    key = "ApiKeyThatCanBePassedAsHeaderIfNecessary",
    body  = "{ ""username"": """ & username & """,  ""password"": """ & password & """, ""key"": """ & key & """}",
    encodedBody = Text.ToBinary(body),
    GetJson = Web.Contents(url,
        [
            Content = encodedBody 
        ]
    )
in
    GetJson 

 

1 Reply