Forum Discussion

bananajams's avatar
bananajams
New Member
5 years ago

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