extract data price with API

Ygor Xavier de Sousa Silva 20 Reputation points
2023-08-15T14:40:36.1666667+00:00

it is possible to extract data from azure like prices of my VM with an api?

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
3,582 questions
{count} votes

Accepted answer
  1. Dillon Silzer 57,826 Reputation points Volunteer Moderator
    2023-08-15T16:01:24.34+00:00

    You will want to use Microsoft Cost Management REST API:

    https://learn.microsoft.com/en-us/rest/api/cost-management/

    Example:

    POST https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/query?api-version=2023-03-01
    
    {
      "type": "Usage",
      "timeframe": "MonthToDate",
      "dataset": {
        "granularity": "Daily",
        "filter": {
          "and": [
            {
              "or": [
                {
                  "dimensions": {
                    "name": "ResourceLocation",
                    "operator": "In",
                    "values": [
                      "East US",
                      "West Europe"
                    ]
                  }
                },
                {
                  "tags": {
                    "name": "Environment",
                    "operator": "In",
                    "values": [
                      "UAT",
                      "Prod"
                    ]
                  }
                }
              ]
            },
            {
              "dimensions": {
                "name": "ResourceGroup",
                "operator": "In",
                "values": [
                  "API"
                ]
              }
            }
          ]
        }
      }
    }
    
    

    Response:

    {
      "id": "providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query/ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
      "name": "ad67fd91-c131-4bda-9ba9-7187ecb1cebd",
      "type": "microsoft.costmanagement/Query",
      "properties": {
        "nextLink": "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/70664866/providers/Microsoft.CostManagement/Query?api-version=2021-10-01&$skiptoken=AQAAAA%3D%3D",
        "columns": [
          {
            "name": "PreTaxCost",
            "type": "Number"
          },
          {
            "name": "ResourceGroup",
            "type": "String"
          },
          {
            "name": "UsageDate",
            "type": "Number"
          },
          {
            "name": "Currency",
            "type": "String"
          }
        ],
        "rows": [
          [
            19.545363672276512,
            "JapanUnifia-Trial",
            20180331,
            "USD"
          ],
          [
            173.41979241290323,
            "RVIIOT-TRIAL",
            20180331,
            "USD"
          ],
          [
            20.35941656262545,
            "VSTSHOL-1595322048000",
            20180331,
            "USD"
          ],
          [
            0.16677720329728665,
            "gs-stms-dev",
            20180331,
            "USD"
          ]
        ]
      }
    }
    

    If this is helpful please accept answer.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.