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
bananajams
New Member

Cost API in government tenant

Hello,

I have a unique problem that Microsoft support hasn't been able to solve.

My goal is to generate cost dashboards in Power BI by accessing an Azure government tenant. I am able to make API calls on the cost usage Microsoft page with the try it now feature and generate the data I would like. I understand the standard cost connectors do not work with government tenants, hence the need to customize this.

It is no problem to connect to the tenant using organizational credentials, however Power BI then tells me "Web.Contents with the Content option is only supported when connecting anonymously." I am using the Web.Contents options to pass the API key and secret, although I am unsure of the correct syntax.

Below are the details:

Power Query

 

let
	url = "https://management.azure.com/subscription/{subscriptionID}/resourceGroups/{RG-name}/providers/Microsoft.CostManagement/query?api-version=2019-11-01",
	body = "{
	""type"": ""Usage"",
	""timeframe"": ""TheLastMonth"",
	""dataset"":
		{
			""granularity"": ""None"",
			""aggregation"":
			{
				""totalCost"":
				{
					""name"": ""PreTaxCost"",
					""function"": ""Sum""
				}
			},
		""grouping"": [
			{
				""type"": ""Dimension"",
				""name"": ""ResourceGroup""
			}
		]
	}
}",
	Parsed_JSON = Json.Document(body),
	BuildQueryString = Uri.BuildQueryString(Parsed_JSON)m
	Source = Json.Document(Web.Contents(url,[Headers = [#"Authentication-Key"="{API-key}", #"Authentication-Secret"="{API-secret}", #"Content-Type"="application/json"], Content = Text.ToBinary(body) ] ))
in
	Source

 

Screenshot of the error

Any guidance is much appreciaed.

Thank you,

S

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @bananajams ,


Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your problem.


Best Regards,
Stephen Tao

v-stephen-msft
Community Support
Community Support

Hi @bananajams ,

 

The error message tells us that the connection is only supported when connecting anonymously. Please check whether your data source supports anonymous connections.

 

Please open Data Source Settings, then find the web data source, choose Anonymous like below: 

q2.PNG

 

Similar posts: https://community.powerbi.com/t5/Desktop/Web-Contents-with-the-Content-option-is-only-supported-when...

https://community.powerbi.com/t5/Desktop/Remote-API-Access-to-data-source-sudden-errors/m-p/627973

 

Best Regards,

Stephen Tao

 

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.

Top Solution Authors