Showing results for 
Search instead for 
Did you mean: 
New Member

Cost API in government tenant


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


	url = "{subscriptionID}/resourceGroups/{RG-name}/providers/Microsoft.CostManagement/query?api-version=2019-11-01",
	body = "{
	""type"": ""Usage"",
	""timeframe"": ""TheLastMonth"",
			""granularity"": ""None"",
					""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) ] ))


Screenshot of the error

Any guidance is much appreciaed.

Thank you,


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

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: 



Similar posts:


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

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors