Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dawidvh
Helper I
Helper I

Power BI Service - Refresh of data on API using POST method

 Hi everyone.

 

We have data that is accessed through a web API using a POST method with a api-key in the header in order to authenticate. This works well from the Power BI desktop, but as soon as the dataset is published to the online Power BI service, the anonymous authentication to the API fails.

Two issues I suspect:

a) The online service might not be passing headers to the API in order to satisfy the api key authentication.

b) The api method that is used by the Power BI Service uses Get by Default, and does not use the Content parameter in the web.contents function to see that it should use a POST request.

 

Does anyone have any workarounds for the above?

 

Below is an example of the query:

2018-08-04_03-22-10.jpg

 

 

Below is the error we are getting on the Power BI service:

2018-08-04_03-28-17.jpg

 

2018-08-04_03-29-32.jpg

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @dawidvh,

 

Based on my research, specify root URL in the url part, and place the remaining URL part into RelativePath parameter, So you can update your code as below. As long as you can use anonymous authentication to access root url of your api, you are able to use anonymous authentication to refresh dataset in Power BI Service.

 

 

let
authKey = “****”,
url =”root url of your api”,
body = “{}”,
Source = Json.Document (Web.Contents(url,[
      Headers = [#”api-key” = authKey,
                           *********
                         #”Content-Type” = “ “application/json”],
      Content = Text . ToBinary(body),
      RelativePath="/api/….."
                    ]
       ) ),
Data = Source[data],

 

For more details, please check this blog.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
LukeM
Regular Visitor

Hi Dawidvh,

I am getting exactly the same problem with the Power Bi Service saying that the credentials are not valid yet everything works fine with Power BI Desktop,  I was wondering if you could explain to me how you solved this problem?

 

Thanks and regards,

Luke

Hi Luke.

 

To get around it you have to use create an intermediatery API that allows anonymous access at root level, that would then in turn connect to your actual data source that doesn't allow anonymous access at root level. Node-Red was perfect for this. Here is a video that you could use to setup Node-Red. https://www.youtube.com/watch?v=zz-jyOih6GA

 

I will try and make a video about connecting Power BI to this in the next week or two. If this is very urgent, let me know so that we can see how we can help or setup a call.

 

v-frfei-msft
Community Support
Community Support

Hi @dawidvh,

 

Based on my research, specify root URL in the url part, and place the remaining URL part into RelativePath parameter, So you can update your code as below. As long as you can use anonymous authentication to access root url of your api, you are able to use anonymous authentication to refresh dataset in Power BI Service.

 

 

let
authKey = “****”,
url =”root url of your api”,
body = “{}”,
Source = Json.Document (Web.Contents(url,[
      Headers = [#”api-key” = authKey,
                           *********
                         #”Content-Type” = “ “application/json”],
      Content = Text . ToBinary(body),
      RelativePath="/api/….."
                    ]
       ) ),
Data = Source[data],

 

For more details, please check this blog.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hi @dawidvh,

 

Does that make sense? If so, kindly mark my answer as a solution to close the case please.

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Hey @v-frfei-msft,

 

I came right, thank you. The problem turned out to be the anonymous access to the root of the API that was not allowed. I have used Node-Red as an API proxy which worked well, but I think this change might be required on the Power BI Service to NOT check the anonymous access against against the root of the API at the time of authenticating from the online service.

 

Have a great day!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors