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
Anonymous
Not applicable

Web.Contents - Sites that do not have an "accessible" endpoint.

Hi all,

 

I've been having luck using the previously mentioned RelativePath to workaround the typical Scheduled Refresh issue encountered when trying to refresh against websites. See here for info Web.Contents(), M Functions And Dataset Refresh Errors In Power BI

 

Where I have had some issues are where the underlying site does not provide a successful 200 response when visiting the base URL.  Typically throwing up a 404 or 403 response and failing the PowerBI service Data source credentials "test".

 

Has anyone found a way around this kind of situation?  Some Power Query M addition that says "Ignore response" or something.

 

For (some) clarity, here is an abridged version of my query: -

let
	TokenBaseURL            = "https://login.microsoftonline.com",
	TokenRelativePath       = "{DirectoryGUID}/oauth2/token",
	TokenContent            = "grant_type=client_credentials&client_id={ClientID}&redirect_uri=https%3A%2F%2Fapi.loganalytics.io&resource=https%3A%2F%2Fapi.loganalytics.io%2F&client_secret={ClientSecret}",
	BaseURL			= "https://api.loganalytics.io",
	RelativePath		= "v1/workspaces/{workspaceID}/query",

    	GetToken =
        	let Options 		= [Content=Text.ToBinary(TokenContent), Headers=[#"Content-Type"="application/x-www-form-urlencoded"], RelativePath=TokenRelativePath],
            		RawData 	= Web.Contents(TokenBaseURL, Options),
            		Document 	= Json.Document(RawData),
            		Token 		= Document[access_token]
        	in Token,

    	GetResults = 
		let Query		= "{""query"": ""CustomLogs|{somequery}""}",
        		Options		= [Content=Text.ToBinary(Query), Headers=[Authorization="Bearer "&GetToken,#"Content-Type"="application/json"], RelativePath=RelativePath],
        		RawData		= Web.Contents(BaseURL, Options),
        		Document	= Json.Document(RawData)
        	in Document

in
	GetResults 

When attempting to add this to app.powerbi.com, I can successfully use login.microsoftonline.com (as it returns a 200 response) but cannot do the same for api.loganalytics.io.

 

Result: -

Failed to update data source credentials: Web.Contents failed to get contents from 'https://api.loganalytics.io/' (404): Not Found

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hopefully, this recent feature will give me the workaround I need.

 

Skip Test Connection for On-premises and Cloud Data Sources

View solution in original post

4 REPLIES 4
TeigeGao
Solution Sage
Solution Sage

Hi @Anonymous ,

Please refer to this document: https://dev.loganalytics.io/, we will need to obtain an authentication token to get data from this site.

Best Regards,

Teige

Anonymous
Not applicable

Hi @TeigeGao ,

 

I am already using the authentication token as per the GetToken function.

This all works fine in Desktop, the problem is when moving it to the online service.

Anonymous
Not applicable

So, I stumbled across an article which helped point me at something that appeared to be of help.

https://prathy.com/2017/09/calling-power-bi-api-using-power-bi-desktop-to-document-power-bi-service/

https://blog.crossjoin.co.uk/2016/08/09/handling-404-not-found-errors-with-web-contents-in-power-que...

Specifically this: - https://docs.microsoft.com/en-us/power-query/waitretry (ManualStatusHandling)

 

However, even with this added, PowerBI Service refuses to accept the data source.

Anonymous
Not applicable

Hopefully, this recent feature will give me the workaround I need.

 

Skip Test Connection for On-premises and Cloud Data Sources

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.