Reply
Frequent Visitor
Posts: 8
Registered: ‎02-16-2016
Accepted Solution

Anonymous access

Hello @Community,

 

I have a power query with a REST api call:

 

 authKey = "Bearer blablablaKey",
 url = "https://blablablaendpoint.com/api/v1/usage/2016",

 GetJsonQuery = Web.Contents(url,
     [
         Headers = [#"Authorization"=authKey, #"Content-Type"="application/json"]
     ]
 ),
FormatAsJsonQuery = Json.Document(GetJsonQuery),

So, this power query use "Anonymous" authentication. When i refresh this query in Power BI Desktop appears credentials error, but if you accept the power query is executed and everything is ok.

But when i try to schedule refresh in Power BI service appears the credentials problems but doesn't exists a way to say "execute anyway".

 

Is like Power BI service checks the anonymous access to the URL and if it doesn't work, power bi doesn't try to execute the power query script.

 

power_bi_erro_01.pngpower_bi_erro_02.pngpower_bi_erro_03.png

 

Please, there is something to do? Power BI team will do something?

 

Thx in advance.


Accepted Solutions
fso Regular Visitor
Regular Visitor
Posts: 23
Registered: ‎10-03-2015

Re: Anonymous access

[ Edited ]

I had the same issue and logged a support ticket with Microsoft because I wanted to build my own Google Analytics queries (include filters, segments, etc).

Here's the answer I got from the support team:
This is not possible due to constraints with the way Web.Contents stores credentials. They are stored based upon the URL value passed, and there can only be one URL per Dataset. In this case, you're trying to short-circuit a typical oAuth2 flow (one URL) and call the API (another URL). I made an attempt at using RelativePath to 'trick' the service, but stills require that the root of those two endpoints returned a valid HTTP 200 response to indicate connection success. In this case, https://www.googleapis.com returns a 404. Unfortunately, therefore it is not possible as an uploaded PBIX file. I suggest creating a new issue describing what data you would want to see in the Google Analytics content pack (https://app.powerbi.com/groups/me/getdata/services/google-analytics) and we can see about adding it to the model.

The only workaround for me so far, is to execute the query elsewhere (for me it's Google Spreadsheet) and connect PBI to that as a data source.

 

View solution in original post


All Replies
Frequent Visitor
Posts: 8
Registered: ‎02-16-2016

Re: Anonymous access

Any help from Microsoft? How i can contact with them?

Regular Visitor
Posts: 36
Registered: ‎02-08-2016

Re: Anonymous access

[ Edited ]

Hi

 

I have this exact same issue.

 

The "authentication" is baked into the Power Query code itself through the API key, so setting the authentication method to anonymous works perfectly in Power BI desktop. However I get the same invalid credentials errors when trying to refresh from Power BI.

 

My code is similar:

Source = Json.Document(Web.Contents("https://myapi.com/api/method", [Headers=[#"X-API-Key"="Some_GUID"]])),

 

If anyone can come up with a workaround for this, I'd be very grateful as well!

 

Duncan

 

EDIT:

Just to note, anonymous authentication works fine at the root level of the api (https://myapi.com/api) and simply lists the methods. However in the Power BI refresh, it tries to load the method url which of course fails without the api key.

fso Regular Visitor
Regular Visitor
Posts: 23
Registered: ‎10-03-2015

Re: Anonymous access

[ Edited ]

I had the same issue and logged a support ticket with Microsoft because I wanted to build my own Google Analytics queries (include filters, segments, etc).

Here's the answer I got from the support team:
This is not possible due to constraints with the way Web.Contents stores credentials. They are stored based upon the URL value passed, and there can only be one URL per Dataset. In this case, you're trying to short-circuit a typical oAuth2 flow (one URL) and call the API (another URL). I made an attempt at using RelativePath to 'trick' the service, but stills require that the root of those two endpoints returned a valid HTTP 200 response to indicate connection success. In this case, https://www.googleapis.com returns a 404. Unfortunately, therefore it is not possible as an uploaded PBIX file. I suggest creating a new issue describing what data you would want to see in the Google Analytics content pack (https://app.powerbi.com/groups/me/getdata/services/google-analytics) and we can see about adding it to the model.

The only workaround for me so far, is to execute the query elsewhere (for me it's Google Spreadsheet) and connect PBI to that as a data source.

 

Regular Visitor
Posts: 36
Registered: ‎02-08-2016

Re: Anonymous access

Well that's actually fixed it for me, so thanks!

 

I've modified my json call to:

Source = Json.Document(Web.Contents("https://myapi.com", [Headers=[#"X-API-Key"="Some_GUID"], 
RelativePath="/api/​method"])),

which now allows it to authenticate properly. In this case I'm lucky that the root url of the api works with anonymous access.

 

 

Duncan

Frequent Visitor
Posts: 8
Registered: ‎02-16-2016

Re: Anonymous access

Indeed, but in my case the root url returns a 401. So i did the workaround that @fso said.

Regular Visitor
Posts: 45
Registered: ‎10-05-2015

Re: Anonymous access

DuncanP,

 

I am trying to solve the same issue, but still getting error, do you mind to write a bit more how you solved this problem please.

 

Dmitry

Regular Visitor
Posts: 36
Registered: ‎02-08-2016

Re: Anonymous access

Hi Dmitry

 

Can you post your code and the issue you're having?

 

Duncan

Regular Visitor
Posts: 45
Registered: ‎10-05-2015

Re: Anonymous access

I was able to fix it using your method.

let
 authKey = "{""Username"":""USERNAME"",""Password"":""PASSWORDGOESHERE"",""LocationID"":""LOCATIONIFNEEDED""}",
 url = "https://APILINKGOESHERE.com",
 // Uses the authentication/token method to obtain a token
 GetJson = Web.Contents(url,
     [
         Headers = [#"Content-Type"="application/json"],
         Content = Text.ToBinary(authKey),
         RelativePath="/Authentication/AuthorizeUser"
     ]
 )
in
    GetJson

So thank DuncanP you for your idea!

 

Regular Visitor
Posts: 36
Registered: ‎02-08-2016

Re: Anonymous access

Glad I could help!

 

Duncan