1
votes

I am using Azure Consumption Usage API to calculate the cost for a resource over a certain span of time, in the response received the cost and effectivePrice value is "0" for every record.

Here is my full url:

GET "https://management.azure.com/subscriptions/{subscriptionsId}/providers/Microsoft.Consumption/usageDetails?$filter=properties/usageStart ge '2019-08-07T00:00:00Z' and properties/usageEnd le '2019-08-09T01:00:00Z'&api-version=2019-05-01"

Here is the response format:

{ "value": [ { "id":"/subscriptions/{subscriptionsId}/providers/Microsoft.Billing/billingPeriods/20190901/providers/Microsoft.Consumption/usageDetails/######-####-####-####-##########", "name":"######-####-####-####-##########", "type":"Microsoft.Consumption/usageDetails", "tags":null, "properties": { "billingAccountId":"*******", "billingAccountName":"*****************", "billingPeriodStartDate":"2019-09-01T00:00:00.0000000Z", "billingPeriodEndDate":"2019-09-30T00:00:00.0000000Z", "billingProfileId":"******", "billingProfileName":"************************", "accountOwnerId":"**********", "accountName":"*************", "subscriptionId":"subscriptioId", "subscriptionName":"subscriptionName", "date":"2019-09-06T00:00:00.0000000Z", "product":"Product Name", "partNumber":"******", "meterId":"meterId", "quantity":0.004032, "effectivePrice":0, "cost":0, "unitPrice":0.045, "billingCurrency":"USD", "resourceLocation":"EastUS", "consumedService":"microsoft.web", "resourceId":"/subscriptions/......", "resourceName":"resourceName", "invoiceSection":"Unassigned", "resourceGroup":"resourceGroupName", "offerId":"MS-AZR-0017P", "isAzureCreditEligible":true, "publisherType":"Azure", "chargeType":"Usage", "frequency":"UsageBased", "meterDetails":null } } ] }

Cost analysis is disabled by the Admin of the subscription, is it why the every record in the response has "cost":0 and "effectivePrice":0 ?

enter image description here

How I can get the cost for a resource using Consumption API?

Can I use the quantity and unitPrice to get the cost for that particular response record?

1

1 Answers

0
votes

I suppose you can't. When clicking Cost analysis in the portal, it also calls the Azure Management REST API(which has a prefix as https://management.azure.com/).

So if the cost is disabled in your subscription, you will not be able to access it via calling the REST API directly, also not other ways like azure powershell, cli, which essentially calls the REST API.