0

For getting the azure subscription billing data I am passing params it's not apply

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"
);
Milo
  • 3,365
  • 9
  • 30
  • 44
Gopal Meena
  • 99
  • 1
  • 7

1 Answers1

0

Please change the format of your params from

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" } ] } }

to

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" } ] } }}

Just add a "{params:" at the beginning and add a "}" at the end.

I think "params" should be a parameter of it. Please have a try.

Hury Shen
  • 14,948
  • 1
  • 9
  • 18