如何通过 SDK 或 API 调用从 Azure 获取价格

How can I get prices from Azure by SDK or API call

你能帮帮我吗?我们有一个第三方工具,它可以连接到 Azure 云。我们可以通过这个工具部署新的云服务、VM等。但是,我想开发一个模块,能够在 UI.

上显示服务器类型(A0、A1、A2、A3 等)的实际价格

使用 Python、JavaScript 或 Curl 以 JSON 或 XML 格式获取它们的最简单方法是什么?

Azure 提供 Usage 和 RateCard API(它们目前处于预览状态)。根据 Azure blog article on Cloudyn -

The Usage API provides access to estimated Azure consumption data for a subscription. The RateCard API provides complete pricing information of all Azure services, for non-Enterprise Agreement (EA) customers.

更多信息 - https://azure.microsoft.com/en-in/documentation/articles/billing-usage-rate-card-overview/

对于您必须发出的 HTTP 请求,请参阅 - https://msdn.microsoft.com/library/azure/1ea5b323-54bb-423d-916f-190de96c6a3c

Azure Billing REST API 会返回一个 JSON 文件,描述(估计!- 我不确定他们为什么估计,但确实如此)服务费率您的订阅。

来自Azure Billing Documentation

Customers and partners can use the Azure Resource RateCard API to get the list of available Azure resources, along with estimated pricing information for each.

为了使用 API,您需要为用户或服务主体配置适当的订阅访问权限

Azure Role-based Access Control - Customers and partners can configure their access policies on the Azure Preview Portal or through Azure PowerShell cmdlets to specify which users or applications can get access to the RateCard data. Callers must use standard Azure Active Directory tokens for authentication. The caller must also be added to either the Reader, Owner or Contributor role to get access to the usage data for a particular Azure subscription.

据我所知,正如@ramiramilu 和@MichaelB 所说,使用 Azure Billing REST API 获取订阅价格是目前唯一的编程方式。

如果您需要一些示例作为参考,Azure 官方 Github 页面上有三个 dotNet 示例,请参阅 https://github.com/Azure/BillingCodeSamples