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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Nari1998
Helper II
Helper II

Error when publishing

Hi everyone i hope all is well. I need some help/guidance regarding a error i get when trying to refresh data that is being fetched through a generated EHS insight Apikey name and key.
Below is the error i get even when using the anonymous authentication:

 

Expression.Error: The 'X-ApiKey' header is only supported when connecting anonymously. These headers can be used with all authentication types: Accept, Accept-Charset, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, If-Modified-Since, Prefer, Range, Referer

Hope to hear from you🥲😅

1 ACCEPTED SOLUTION
Nari1998
Helper II
Helper II

Hi @v-nuoc-msft ,

 

 

Thank you for the detailed explanation on this. I will try it next time. For now we just removed the api header and key from all sources and then changed the authentication to basic where we just gave a username and the api key as password and all seemed to be working well now.

View solution in original post

2 REPLIES 2
Nari1998
Helper II
Helper II

Hi @v-nuoc-msft ,

 

 

Thank you for the detailed explanation on this. I will try it next time. For now we just removed the api header and key from all sources and then changed the authentication to basic where we just gave a username and the api key as password and all seemed to be working well now.

v-nuoc-msft
Community Support
Community Support

Hi @Nari1998 

 

I understand that you are getting an error when trying to refresh data from a web API using an EHS insight Apikey name and key.

 

Based on the error message, it seems that Power BI is not recognizing the ‘X-ApiKey’ header as a valid authentication method for the web API.

 

Power BI only supports a few standard headers for web API authentication, such as Authorization, Cookie, or X-HTTP-Method. For other headers, such as X-ApiKey, Power BI will throw an error unless you connect anonymously.

 

However, connecting anonymously is not a secure or recommended way to access web APIs that require authentication. A better solution would be to use the Web.Contents function in Power Query to specify the custom header for the web API.

 

This function allows you to pass additional options for the web API request, such as headers, query parameters, or content type.

 

To use the Web.Contents function, you need to edit the query that connects to the web API in Power Query Editor. You can do this by following these steps:

 

In Power BI Desktop, go to the Home tab and click on Transform Data.


In Power Query Editor, select the query that connects to the web API and go to the Advanced Editor.


In the Advanced Editor, replace the existing code with the following code:

 

let
    Source = Web.Contents("1", [Headers=[#"X-ApiKey"="your_api_key"]])
in
    Source

 

In Power Query Editor, go to the Home tab and click on Close & Apply.


This should allow you to refresh the data from the web API without getting the error.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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