SOLVED
Home

Azure Cost Management API

%3CLINGO-SUB%20id%3D%22lingo-sub-1104933%22%20slang%3D%22es-ES%22%3EAzure%20Cost%20Management%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1104933%22%20slang%3D%22es-ES%22%3E%3CP%3E%3CSPAN%3EDoes%20anyone%20know%20how%20to%20get%20an%20access%20token%20to%20access%20that%20endpoint%20and%20those%20who%20are%20also%20on%20the%20page%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EGET%20%3CA%20href%3D%22https%3A%2F%2Fmanagement.azure.com%2Fproviders%2FMicrosoft.Billing%2FbillingAccounts%2F%7BbillingAccountName%7D%2Fcustomers%3Fapi-version%3D2019-10-01-preview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmanagement.azure.com%2Fproviders%2FMicrosoft.Billing%2FbillingAccounts%2F%3FbillingAccountName%2Fcustomers%3Fapi-version-2019-10-01-preview%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcost-management%2Fget-started-partners%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcost-management%2Fget-started-partners%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1104933%22%20slang%3D%22es-ES%22%3E%3CLINGO-LABEL%3EAPI%20Management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1106203%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Cost%20Management%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1106203%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F513947%22%20target%3D%22_blank%22%3E%40jroberts1010%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETry%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24azContext%20%3D%20Get-AzContext%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24azProfile%20%3D%20%5BMicrosoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider%5D%3A%3AInstance.Profile%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24profileClient%20%3D%20New-Object%20-TypeName%20Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient%20-ArgumentList%20(%24azProfile)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24token%20%3D%20%24profileClient.AcquireAccessToken(%24azContext.Subscription.TenantId)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24authHeader%20%3D%20%40%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'Content-Type'%3D'application%2Fjson'%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20'Authorization'%3D'Bearer%20'%20%2B%20%24token.AccessToken%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%7D%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24url%20%3D%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmanagement.azure.com%2Fproviders%2FMicrosoft.Billing%2FbillingAccounts%2F%26gt%3BbillingAccountName%26gt%3B%2Fcustomers%3Fapi-version%3D2019-10-01-preview%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22courier%20new%2Ccourier%22%20size%3D%221%202%203%204%205%206%207%22%3E%24response%20%3D%20Invoke-RestMethod%20-Uri%20%24url%20-Method%20Get%20-Headers%20%24authHeader%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1107741%22%20slang%3D%22es-ES%22%3ERe%3A%20Azure%20Cost%20Management%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1107741%22%20slang%3D%22es-ES%22%3E%3CP%3Eyes%2C%20i%20understand%20but%2C%20i%20need%20to%20call%20that%20endpoint%20on%20a%20controller%20from%20an%20application%20in%20c....%20is%20that%20possible%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1109032%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Cost%20Management%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1109032%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20it%20is%20possible%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F513947%22%20target%3D%22_blank%22%3E%40jroberts1010%3C%2FA%3E.%26nbsp%3BAzure%20SDK%20for%20.NET%20(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Foverview%2Fazure%2Fbilling%3Fview%3Dazure-dotnet%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EBilling%3C%2FA%3E%20%2B%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Foverview%2Fazure%2Fconsumption%3Fview%3Dazure-dotnet%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EConsumption%3C%2FA%3E)%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
jroberts1010
New Contributor
3 Replies
Highlighted

@jroberts1010 

 

Try this:

 

$azContext = Get-AzContext

$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile

$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)

$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)

$authHeader = @{

    'Content-Type'='application/json'

    'Authorization'='Bearer ' + $token.AccessToken

}

 

$url = https://management.azure.com/providers/Microsoft.Billing/billingAccounts/>billingAccountName>/custom...

$response = Invoke-RestMethod -Uri $url -Method Get -Headers $authHeader

Highlighted

yes, i understand but, i need to call that endpoint on a controller from an application in c#....is that posible?

Highlighted
Solution

Yes it is possible, @jroberts1010. Azure SDK for .NET (Billing + Consumption)