Forum Discussion
API authentication error on scheduled refresh
- 2 months ago
Hi Rabi , Your M query looks correct, so the issue is probably no longer the Web.Contents syntax itself. Since the error still occurs when creating the connection in the Service, Power BI is likely failing the datasource validation against the API endpoint rather than the refresh query.
Many APIs require the custom headers (X-Api-Key and X-Tenant) on every request, but Power BI Service test connection does not always include those headers during validation. Check whether the API root URL can be accessed without headers, if there are any firewall/IP restrictions blocking Power BI Service and whether Skip test connection can be enabled in your tenant/gateway settings. If the API only works when those headers are present, you may ultimately need a custom connector or gateway-based approach because some header-authenticated APIs do not validate cleanly with anonymous web connections in the Service.
Skip Test Connection for On-premises and Cloud Dat... - Microsoft Fabric Community
Hi Rabi , Thank you for reaching out to the Microsoft Community Forum.
Power BI Service handles Web.Contents differently than Desktop and often fails scheduled refresh when the full URL is embedded directly in the function. Keep the base domain static and move the endpoint into RelativePath, then configure the datasource in the Service as Anonymous. Your custom headers (X-Api-Key and X-Tenant) can still be passed in the Headers record.
After publishing, reconfigure the dataset credentials in the Service as Anonymous and set the privacy level to Organizational or Public. In most cases this resolves the refresh issue.
Hi Everyone,
Thanks for your suggestions I am still getting the exact same error;
I have used the following query, I also tried "https://api.csassurance.com" as a base URL.
let
BaseUrl = "https://api.csassurance.com/",
Source =
Json.Document(
Web.Contents(
BaseUrl,
[
RelativePath = "api/v2/reports/ReportUUIDHere/snapshot",
Headers = [
#"X-Api-Key" = "APIHere",
#"X-Tenant" = "ABC"
]
]
)
)
in
SourceThanks !
- v-hashadapu2 months agoCommunity Support
Hi Rabi , Your M query looks correct, so the issue is probably no longer the Web.Contents syntax itself. Since the error still occurs when creating the connection in the Service, Power BI is likely failing the datasource validation against the API endpoint rather than the refresh query.
Many APIs require the custom headers (X-Api-Key and X-Tenant) on every request, but Power BI Service test connection does not always include those headers during validation. Check whether the API root URL can be accessed without headers, if there are any firewall/IP restrictions blocking Power BI Service and whether Skip test connection can be enabled in your tenant/gateway settings. If the API only works when those headers are present, you may ultimately need a custom connector or gateway-based approach because some header-authenticated APIs do not validate cleanly with anonymous web connections in the Service.
Skip Test Connection for On-premises and Cloud Dat... - Microsoft Fabric Community