'Pricing API for Azure

Is there a pricing api for azure similar to what AWS has for product listing and pricing catalog.For example to get EC2 pricing and product catalog AWS gives a JSON/CSV file , Wondering if there is anything similar for Azure



Solution 1:[1]

https://prices.azure.com/api/retail/prices

you can use query to read particular item like below

https://prices.azure.com/api/retail/prices?$filter=ArmRegionName%20eq%20%27eastus%27

Solution 2:[2]

You can use the consumption API Usage Details - List

GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?api-version=2019-01-01

Here is the documentation.

if you want to see the usage details, use the api

Get Virtual Machine usage metrics using the REST API

Solution 3:[3]

Use the Azure Consumption Price Sheet API:

GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/pricesheets/default?api-version=2019-10-01

Use the expand parameter, you will get a list of pricing looking like this:

{
    "billingPeriodId": "/subscriptions/XXXX-XXXXX-XXX-XXXXX/providers/Microsoft.Billing/billingPeriods/20191001",
    "currencyCode": "EUR",
    "includedQuantity": "0",
    "meterDetails": {
        "meterCategory": "Virtual Machines",
        "meterLocation": "US East",
        "meterName": "D2s v3",
        "meterSubCategory": "Dv3 VDI Series Windows",
        "pretaxStandardRate": "None",
        "totalIncludedQuantity": "None",
        "unit": "10 Hours"
    },
    "meterId": "YYYYYY-YYYYY-YYYYYYYYYYY-YYYYYY",
    "partNumber": "AAD-3489577",
    "unitOfMeasure": "10 Hours",
    "unitPrice": "0.834958995845993200054867"
},

See also this stackoverflow question: How to get Azure service pricing details programmatically?.

Solution 4:[4]

Here is the official documentation

https://docs.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices

Example apis(you don't need an azure account to hit these apis) "https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Virtual Machines' and priceType eq 'Reservation'"

"https://prices.azure.com/api/retail/prices?$filter=serviceFamily eq 'Storage'"

"https://prices.azure.com/api/retail/prices?$filter=serviceFamily eq 'Compute'"

"https://prices.azure.com/api/retail/prices?$filter=endswith(armRegionName, 'europe')"

Solution 5:[5]

If anyone is trying to use PowerShell to call this API, here is a way of doing it.

I was getting {"Error":{"Code":"BadRequest","Message":"Invalid OData parameters supplied"}} because I was being stupid and not escaping the $ in $filter with a backtick (`).

$Currency = "GBP"
$Region = "uksouth"
$EndpointUri = "https://prices.azure.com/api/retail/prices?api-version=2021-10-01-preview&currencyCode=$Currency&`$filter=serviceName eq 'Virtual Machines' and ArmRegionName eq '$Region'"

$oRequest = $null
$oRequest = Invoke-RestMethod -Uri $EndpointUri -Method Get -Verbose
$oRequest

This will return something like:

BillingCurrency    : GBP
CustomerEntityId   : Default
CustomerEntityType : Retail
Items              : {@{currencyCode=GBP; tierMinimumUnits=0; retailPrice=0.4058; unitPrice=0.4058; armRegionName=uksouth; location=UK South;
                     effectiveStartDate=01/11/2021 00:00:00; meterId=001fa6ba-405f-5854-9dd5-5ecd8a7d7ef3; meterName=D48s v5 Low Priority;
                     productId=DZH318Z08M9T; skuId=DZH318Z08M9T/000W; productName=Virtual Machines Dsv5 Series Windows; skuName=Standard_D48s_v5 Low
                     Priority; serviceName=Virtual Machines; serviceId=DZH313Z7MMC8; serviceFamily=Compute; unitOfMeasure=1 Hour; type=DevTestConsumption;   
                     isPrimaryMeterRegion=True; armSkuName=Standard_D48s_v5}…}
NextPageLink       : https://prices.azure.com:443/api/retail/prices?api-version=2021-10-01-preview&currencyCode=GBP&$filter=serviceName%20eq%20%27Virtual%20
                     Machines%27%20and%20ArmRegionName%20eq%20%27uksouth%27&$skip=100
Count              : 100

HTH.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Machavity
Solution 2 Sajeetharan
Solution 3
Solution 4 aswin_tp
Solution 5 woter324