I am trying to use the Microsoft.Azure.Management.Consumption 3.0.2 package to access the usage and consumption data.
However in the call to UsageDetails.List
I get the following error:
Subscription scope usage is not supported for current api version. Please use api version after 2019-10-01
Is there a new version of the package (or is there expected to be) that supports this version?
What alternatives do I have in the meantime?
I can directly use a GET against
https://management.azure.com/subscriptions/<subscriptionId>/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01
but is there any other option?
UPDATED WITH CODE
Request code:
AuthenticationResult result = GetToken();
Microsoft.Rest.TokenCredentials tokenCredentials = new
Microsoft.Rest.TokenCredentials(result.AccessToken);
ConsumptionManagementClient client = new
ConsumptionManagementClient(tokenCredentials);
client.SubscriptionId = "SubscriptionId I would like to check";
var usage = client.UsageDetails.List(); // Exception here with API Version
Auth Code sample:
private static AuthenticationResult GetToken()
{
string clientId = "MyappId";
string[] scopes = new string[] { "https://management.azure.com/.default" };
var app = PublicClientApplicationBuilder
.Create(clientId)
.WithRedirectUri("https://localhost")
.WithTenantId("TenantId I want to check")
.Build();
var task = app.GetAccountsAsync();
task.Wait();
var accounts = task.Result;
try
{
var task1 = app.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync();
task1.Wait();
return task1.Result;
}
catch (MsalUiRequiredException)
{
var task2 = app.AcquireTokenInteractive(scopes).ExecuteAsync();
task2.Wait();
return task2.Result;
}
}