how to get Azure Offer ID(Billing Rate card API) using rest api

Deepak Patil 41 Reputation points
2021-05-25T06:32:00.673+00:00

We have one tenant id and under that we have around 400 subscriptions. While accessing rate card api GET https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/RateCard?api-version={api-version}&$filter=OfferDurableId eq ’{OfferDurableId}’ and Currency eq ’{Currency}’ and Locale eq ’{Locale}’ and RegionInfo eq ’{RegionInfo}’’

we need OfferDurableId. SO is there any way by rest api we can get OfferDurableId? because we are accessing this api daily and it need OfferDurableId. it is not feasible to to keep all offerID around 400 for all subscriptions.

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,477 questions
{count} votes

Accepted answer
  1. SadiqhAhmed-MSFT 44,176 Reputation points Microsoft Employee
    2021-06-04T05:30:52.983+00:00

    @Deepak Patil Sorry for the delayed response!

    The right approach here would be to have you move to the updated APIs that are used. If you want to look at the relevant APIs that are being replaced the current documents here point to the newer versions

    Resource RateCard (Preview) | Microsoft Learn
    Resource Usage (Preview) | Microsoft Learn

    ----------------------------------------------------------------------------------------------------------------------

    If the response helped, do "Accept Answer" and up-vote it

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deepak Patil 41 Reputation points
    2021-05-28T20:02:12.89+00:00

    @ SadiqhAhmed-6187 Currently we are using rate card api to get calculate monthly billing for all subscriptions under tenant. First we hit RateCard Api to get all the rates using GET https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/RateCard?api-version={api-version}&$filter=OfferDurableId eq ’{OfferDurableId}’ and Currency eq ’{Currency}’ and Locale eq ’{Locale}’ and RegionInfo eq ’{RegionInfo}’’ and then in response we got json having one of the property as "MeterRates": {
    "0": 0.71
    },

    After this we hit GET https://management.azure.com/subscriptions/{subscription-Id}/providers/Microsoft.Commerce/UsageAggregates?api-version={api-version}&reportedStartTime={dateTimeOffset-value}&reportedEndTime={dateTimeOffset-value}&aggregationGranularity={granularity-value}&showDetails={showdetail-boolean-Value}&continuationToken={token-value} i .e resource usage api to get the usages having granularity as hours. In response we get "quantity": 0.057865 field.

    Doc reference for usage api:https://video2.skills-academy.com/en-us/previous-versions/azure/reference/mt219001(v=azure.100)

    so we do little math :---MeterRate(which we get from 1st api)*quantity to get the actual billing for that resource.

    So our aim is to calculate last 30 days billing for my subscription. so we get hourly usage data by setting granularity to hour in usage request filter for last 30 days and then multiply with rate ...so we have hourly cost of that resource ...store in db this hourly data and the sum all the price calculated for that resource for last 30 days.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.