cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cwebb
Advisor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

I've just tested this again and my original example still works with the ApiKeyName option, so I'm not sure what the problem is in your case. In any case I'm not sure this will solve your original problem... Let me see if I can get someone from Microsoft to comment.

 

Chris

cwebb
Advisor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

I just did a few more tests, and it looks like using the ApiKeyName option isn't supported in the Power BI service anyway. However I was able to publish a report that uses the Headers option to pass an API key and that refreshes ok.

 

One thing though: after you published to the Power BI service, did you go into the settings for the data source in the browser and configure the data source credentials again? You can find this by clicking on the ellipses (...) next to the datset in the browser, choosing Schedule Refresh and opening the Data Source credentials section. You'll have to set the credentials to Anonymous again.

 

Chris

adam_abenius Frequent Visitor
Frequent Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

Hi Chris, thanks for your effort!

 

Yes I did try to set the credentials, but its failing... I dont know if the service for some security reason blanks M-code containing Header-information when uploading to PBI service? It's really odd..

 

J21Cy0x

cwebb
Advisor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

It can't be blanking out the header information because, as I said, I've just tested it and it works for me. Strange...

 

Can you post more of the M code for your query?

adam_abenius Frequent Visitor
Frequent Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

let
    Source = Json.Document(Web.Contents("<<API-URL>>", [Headers=[#"Authorization"="Token <<API-TOKEN>>"]])),
    toTable = Table.FromRecords({Source})
in
    toTable

I stripped the code down to the basics, still giving me the error :/. What you see above is the only thing going on in the file. The only thing I could think of is the fact that the information that is passed in the Autorization-tag is "Token <<API-TOKEN>>". It's not just plainly a API-key since it starts with the word "Token" and is followed by the actual key, I dont know if that is even possible to be an issue?

cwebb
Advisor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

Hmm, one last guess - can you try separating the call to Web.Contents() from Json.Document()? ie something like this:

 

let
    Source = Web.Contents("<<API-URL>>", [Headers=[#"Authorization"="Token <<API-TOKEN>>"]]),
    convertToJson = Json.Document(Source),
    toTable = Table.FromRecords({convertToJson})
in
    toTable
Highlighted
beneuto Regular Visitor
Regular Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

I also have this issue when trying to publish to server.

 

If I try to use the APiKeyName option then Desktop complains that only Anonymous access is allowed for PUT requests so I am forced to hardcode the token into the header.   Despite this insistance on Anonymous access, Server insists that I provide credentials for the website but if I try to use the Anonymous option it fails.

 

And this is trying to connect to Microsoft's own Cognitive Services APIs.

 

 

rdeken Frequent Visitor
Frequent Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

I'm having the same problem with a different RESTful web service.  Works in PBI Desktop but can't specify anonymous credentials on PowerBI.com.

sasmpu00 Frequent Visitor
Frequent Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

Hello,

 

I am trying to get JSON from VSTS REST API. But I am not getting jason while using it power BI. It, returing web page content which is basically log in page. The below code, I have used. Could you please help me what I am missing.. 

 

Try 1:
let
authKey = "{""Username"":""XX"",""Password"":""XXX""}",
url = "https://davidscotttest.visualstudio.com/DefaultCollection/_apis/wit/workItems/12",
// Uses the authentication/token method to obtain a token
GetJson = Json.Document(Web.Contents(url,
[
Headers = [#"Content-Type"="application/json"],
Content = Text.ToBinary(authKey),
RelativePath="/Authentication/AuthorizeUser"
]
))
in
GetJson

 

try 2:

let
result = Web.Contents("https://davidscotttest.visualstudio.com/DefaultCollection/_apis/wit/workItems/12",[Headers=[#"Author... zc4cqxzc2k522zfzpueslrn3e3dvaxgxntpcnujnboksj7yico3a"]])
in
result


try 3:


let
result = Json.Document(Web.Contents("https://davidscotttest.visualstudio.com/DefaultCollection/_apis/wit/workItems/12", [Headers=[#"Authorization"="Token zc4cqxzc2k522zfzpueslrn3e3dvaxgxntpcnujnboksj7yico3a"]]))

in
result

beneuto Regular Visitor
Regular Visitor

Re: web.contents with specified headers works in PBI desktop but fails in PBI Web

Suggest you raise another thread as this is not really on topic.   That being said, you may wish look at the VSTS data source provided in Power BI rather than using the Web source.