A simple library allowing you to send a request to the Azure RateCard API through node.js
- You should have an Azure Subscription
- You should have registered an application into the Azure AD tenant related to your subscription as described here https://docs.microsoft.com/en-us/rest/api/index?redirectedfrom=MSDN#register-your-client-application-with-azure-ad/
- Please keep the Application ID
- Create a Key and keep it as well
- Since you're working on the Azure AD tenant please keep the AAD tenant ID as well :-)
- You should have added the Azure AD application freshly registered to the IAM of your subscription with sufficient privileges (Reader role is fine)
npm install --save azure-ratecard-api-wrapper
- After doing the prerequisite and installing the package you'll be able to use the only exported method
GetPriceAndMetadataInformation
is exported and expect a parameters object & a callback
let GetPrices = require("azure-ratecard-api-wrapper").GetPriceAndMetadataInformation;
let params =
{
aad_tenant_id : "AAD_TENANT_ID",
application_id : "AAD_REGISTERED_APP_ID",
application_secret : "AAD_REGISTERED_APP_SECRET",
subscription_id : "AZURE_SUBSCRIPTION_ID",
offer_id : "MS-AZR-0003P",
currency : "EUR",
locale : "en-us",
region : "FR"
}
GetPrices(params, function(result)
{
// Handle the error if any.
if (result instanceof Error)
{
console.log("Error : " + result.message);
return;
}
// Work with the result.
console.log("VM A0 Windows in US West price is "
+ result.VirtualMachines.A0VMWindows.ComputeHours.USWest.Value
+ " " + params.currency
+ " per " + result.VirtualMachines.A0VMWindows.ComputeHours.USWest.Unit);
});
result
object hold the category, subcategory, region and tier for Azure services- Syntax is
result.<category : service or group of services>.<subcategory : tier or service>.<billing unit>.<azure region>.<Unit or Value field>
- The list of all fields is available at https://github.com/olileger/azure-ratecard-api-wrapper/blob/master/lib/references.txt
- The
result
doesn't include rates tagged as 'Deprecated'
- Tests are implemented using Mocha & Chai
npm test
will execute the test code under\test
directorygetprice-config.js
file should be customized with your own values especially for :aad_tenant_id
matching your Azure AD directory idapplication_id
matching your Application Id as mentionned in the 'Before Using The Package' sectionapplication_secret
matching your Application Secret as mentionned in the 'Before Using The Package' sectionsubscription_id
matching the Azure subscription id under which the application got the 'Reader' role