Forum Discussion
Error when publishing
- 2 years ago
Hi Anonymous ,
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.
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.