none
Cannot get Azure billing API to work (Resource RateCard) RRS feed

  • Question

  • From an app. I am trying to retrieve cost info for hosting for example a virtual server in Azure.
    I found this API, that apparently should deliver the info, but my problem is I always get the error: Invalid query specified. Please specify a valid filter in format of $filter

    I have tried to copy the examples as is. Additionally I tried various types of apostrophes, curriencies, locations (both country codes and Azure locations ex. US West).

    My PS example code is as follows:

    $Headers = @{}
    $Headers.Add("authorization", "bearer eyJ0....")
    $content = Invoke-WebRequest -Uri "https://management.azure.com/subscriptions/<subscription guid>/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'DKK' and Locale eq 'en-US' and RegionInfo eq 'DK'" -Headers $Headers

    Access token has been obtain by using AuthenticationContext and AcquireTokenAsync, by using a service principal.
    Service principal has read access to my subscription.

    Any ideas what wrong with the filter?

    Alternatively I will have to get the data from https://ea.azure.com/rest/...
    However I cannot find a way to grant access to a service principal. And then my app. will need a fixed expiring token just for this.

    Sunday, October 23, 2016 11:41 AM

All replies

  • Got it working.
    Moved the code to C# where I am also getting the access token:

    HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Add("authorization", "bearer " + strAccessToken);
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage response = await client.GetAsync("https://management.azure.com/subscriptions/<subscription guid>/providers/Microsoft.Commerce/RateCard?api-version=2016-08-31-preview&$filter=OfferDurableId eq 'MS-AZR-0003P' and Currency eq 'DKK' and Locale eq 'en-US' and RegionInfo eq 'DK'");
    
    Looks the same to me, but now it is working.

    Sunday, October 23, 2016 9:58 PM