Forum Discussion
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:
- 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.
- 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.
- 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
- AnonymousNot applicable
Hi kramaswamy7 ,
If you have a Web connector script that's using the Web.Page function, and you have updated your dataset or report after November 18th, 2016, you must use a gateway for refresh to work properly.
Web.BrowserContents is similar in function to Web.Page, if you only use Web.Contents, there is no need for a gateway.
For more information,you can refer to:
Revisiting Dynamic Web.Contents()
Web.Contents(), M Functions And Dataset Refresh Errors In Power BI
Dynamic Web.Contents() and Power BI Refresh Errors
Hope it helps,
Community Support Team _ CaitlynIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.