如何在获取帐单数据天蓝色功能时传递参数

时间:2019-08-26 06:37:01

标签: azure azure-functions azure-billing-api

为了获取天蓝色的订阅计费数据,我正在传递参数,但这并不适用

const axios = require('axios');
  let usage = [];
 function getUsage(subscriptionId, accessToken) {
  const url = `https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.Consumption/usageDetails?api-version=2019-01-01`

  const options = {
    headers: {
      Authorization: `Bearer ${accessToken}`
    }
   }

// I am trying to pass data for filtering
   const params  ={
    type: "Usage",
    timeframe: "MonthToDate",
    dataset: {
      granularity: "None",
      aggregation: {
        totalCost: {
          name: "PreTaxCost",
          function: "Sum"
        }
      },
      grouping: [
        {
          type: "Dimension",
          name: "MeterCategory"
        },
         {
          type: "Dimension",
          name: "ResourceLocation"
        },
         {
          type: "Dimension",
          name: "ResourceGroup"
        }    ]
    }
  }
  axios.get(url, options, params).then(response => {
    console.log('response.data------', response.data);
  }).catch(error => {
    console.log(error);
  });
}
//calling API here
await getUsage(
  "subscriptionId",
  "access-token"
);

1 个答案:

答案 0 :(得分:0)

请更改您的参数格式

params ={ type: "Usage", timeframe: "MonthToDate", dataset: { granularity: "None", aggregation: { totalCost: { name: "PreTaxCost", function: "Sum" } }, grouping: [ { type: "Dimension", name: "MeterCategory" }, { type: "Dimension", name: "ResourceLocation" }, { type: "Dimension", name: "ResourceGroup" } ] } }

params ={params:{ type: "Usage", timeframe: "MonthToDate", dataset: { granularity: "None", aggregation: { totalCost: { name: "PreTaxCost", function: "Sum" } }, grouping: [ { type: "Dimension", name: "MeterCategory" }, { type: "Dimension", name: "ResourceLocation" }, { type: "Dimension", name: "ResourceGroup" } ] } }}

只需在开头添加“ {params:”,然后在末尾添加“}”。

我认为“ params”应该是它的参数。请尝试一下。