To fetch the estimated price of a VM, license cost with committed discounts, you can use the Azure Pricing Calculator API. This API allows you to programmatically retrieve pricing information for Azure services, including virtual machines and software licenses.
Here's an example of how to use the Azure Pricing Calculator API to retrieve pricing information for a virtual machine:
First, you need to get an API key for the Azure Pricing Calculator API. You can get the API key by following the instructions in the Azure Pricing Calculator API documentation.
- Once you have the API key, you can use it to make a REST API call to the Azure Pricing Calculator API. Here's an example of the API call to retrieve pricing information for a virtual machine:
GET https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Virtual Machines' and armSkuName eq 'Standard_D2_v3' and armRegionName eq 'eastus' and priceType eq 'Consumption' and termType eq '1 Year' and includedQuantity eq 1 and isPrimaryMeterRegion eq true and currencyCode eq 'USD' and priceDate eq '2022-01-01T00:00:00Z'&$top=1&$skip=0&$orderby=unitPrice asc&$select=unitPrice
In this example, the API call retrieves pricing information for a Standard_D2_v3 virtual machine in the East US region, with a 1-year commitment and 1 unit of quantity. The API call also specifies that the price should be returned in USD and that the price date is January 1, 2022.
- Once you make the API call, you will receive a JSON response that contains the pricing information for the virtual machine. Here's an example of the JSON response:
{
"Items": [
{
"unitPrice": 0.064
}
]
}
In this example, the unit price for the virtual machine is $0.064 per hour.
You can modify the API call to retrieve pricing information for different virtual machine sizes, regions, commitment terms, and quantities. You can also use the API to retrieve pricing information for other Azure services, such as software licenses.
Hope this helps!
If the response helped, do "Accept Answer" and up-vote it