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
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
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.