简体   繁体   中英

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. According to documentation here: 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.

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. 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.

I just ran that code again, with and without stream reader and it works fine. I guess the folks at Microsoft had an issue and corrected it. Still no filtering capability, but I can do that client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM