[英]Microsoft rate card api appears broken. Returning partial response
I am attempting to get pricing details for my subscription by accessing the management.azure.com api.我正在尝试通过访问 management.azure.com api 来获取我的订阅的定价详细信息。 According to documentation here: https://docs.microsoft.com/en-us/previous-versions/azure/reference/mt219004(v=azure.100)?redirectedfrom=MSDN根据此处的文档: https://docs.microsoft.com/en-us/previous-versions/azure/reference/mt219004(v=azure.100)?redirectedfrom=MSDN
I have attempted hitting API with provided code, Postman and 3rd party library ( https://github.com/codehollow/AzureBillingApi/ ) all resulting in a bad response that cannot be deserialized.我尝试使用提供的代码 API、Postman 和第三方库( https://github.com/codehollow/AzureBillingApi/这一切都无法消除不良响应)。
Proto code is as follows:原型代码如下:
AzureCredentials credentials = credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud).WithDefaultSubscription(subscriptionId);
ServiceClientCredentials serviceClientCredentials = await await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
string urlString = @$"https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId eq 'MS-AZR-0003p' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US' and MeterCategory eq 'Storage'";
using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, urlString))
{
await serviceClientCredentials.ProcessHttpRequestAsync(requestMessage, CancellationToken.None);
using (HttpClient client = new HttpClient())
{
HttpResponseMessage responseMessage = await client.SendAsync(requestMessage);
if(!responseMessage.IsSuccessStatusCode)
throw new InvalidOperationException(responseMessage.ReasonPhrase);
string contentString = await responseMessage.Content.ReadAsStringAsync();
RateCardResponse rateCardResponse = JsonConvert.DeserializeObject<RateCardResponse>(contentString);
}
}
While I get a valid response (200) the contentString variable is invalid JSON.虽然我得到一个有效的响应 (200),但 contentString 变量是无效的 JSON。 Example has been shortened for readability.为了便于阅读,示例已被缩短。
{
"OfferTerms": [],
"Meters": [
{
"EffectiveDate": "2020-05-01T00:00:00Z",
"IncludedQuantity": 0.0,
"MeterCategory": "Virtual Machines",
"MeterId": "cd2d7ca5-2d4c-5f93-94d0-8cee0662c71c",
"MeterName": "E20 v4",
"MeterRates": {
"0": 1.52
},
"MeterRegion": "AP Southeast",
"MeterStatus": "Active",
"MeterSubCategory": "Ev4 Series",
"MeterTags": [],
"Unit": "1 Hour"
},
{
"EffectiveDate": "2020-11-01T00:00:00Z",
"IncludedQuantity": 0.0,
"MeterCategory": "Virtual Machines Licenses",
"MeterId": "e8ceef66-d651-5a3c-9af9-046917e3a466",
"MeterName": "104 vCPU License",
"MeterRates": {
"0": 1.456
},
"MeterRegion": <ACTUAL RESPONSE IS 627,746 bytes but always cuts off at this point>
This site ( https://azureprice.net/ ) appears to be pulling recent details from same API without issues, but I am stumped why my response is cut off and invalid.这个网站( https://azureprice.net/ )似乎从同一个 API 中提取最近的细节没有问题,但我很难过为什么我的回复被切断和无效。
I just ran that code again, with and without stream reader and it works fine.我只是再次运行该代码,无论是否使用 stream 阅读器,它都可以正常工作。 I guess the folks at Microsoft had an issue and corrected it.我猜微软的人遇到了问题并纠正了它。 Still no filtering capability, but I can do that client side.仍然没有过滤能力,但我可以做那个客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.