Azure Cost Management Export Run Failing - Cost Export API

praveen 15 Reputation points
2023-03-14T07:52:21.97+00:00

Hi, I am trying to programmatically create and execute Azure Cost Management Export using the Azure Cost Exports REST API. The custom cost export is being created successfully via the API but when I am trying to execute the job run via API (tried running the job multiple times via the api) it is throwing An unknown error occurred in the cost management console. The same cost export when I go to edit details and save it via the console (without changing the existing configuration set through API) the next run is executing successfully, however the subsequent api calls are failing.

API - Execute

Azure-CostIssue

Tried to debug the issue using get-execution-history api but couldn't find anything useful in the response. However, I am attaching few of the fields from the response, which I feel might be helpful in reviewing this issue.

{
  "value": [
    {
      "properties": {
        "error": {
          "code": "NotDefined"
        },
        "executionType": "OnDemand",
        "processingEndTime": "2023-03-09T06:47:33.4996414Z",
        "processingStartTime": "2023-03-09T06:47:23.1083921Z",
        "runSettings": {
          "definition": {
            "timeframe": "Custom",
            "type": "Usage",
            "dataSet": {
              "configuration": {
                "columns": []
              },
              "granularity": "Daily"
            },
            "timePeriod": {
              "from": "2022-12-28T12:42:00Z",
              "to": "2023-02-04T00:00:00Z"
            }
          },
          "format": "Csv"
        },
        "status": "Failed",
        "submittedTime": "2023-03-09T06:47:22.8421712Z"
      }
    }
  ]
}

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

1 answer

Sort by: Most helpful
  1. PFS 0 Reputation points
    2023-11-08T01:33:52.3166667+00:00

    Same problem here. I have created a costs management export via the API based on the code here

    The Export creates without any errors, but the scheduled execution fails with "Unknown error occurred"

    When I Edit the export in the Azure portal (by clicking the Edit link) and just save the export without changing anything, and then run the export it works.

    UPDATE:

    I have removed the Column list from my code and now it works:

                    Definition = new ExportDefinition(ExportType.ActualCost, TimeframeType.MonthToDate)
                    {
                        DataSet = new ExportDataset()
                        {
                            Granularity = GranularityType.Daily
                            //,
                            //Columns = 
                            //    {
                            //      "InvoiceId","PreviousInvoiceId","BillingAccountId","BillingAccountName","BillingProfileId","BillingProfileName","InvoiceSectionId","InvoiceSectionName","ResellerName","ResellerMPNId","CostCenter","BillingPeriodEndDate","BillingPeriodStartDate","ServicePeriodEndDate","ServicePeriodStartDate","Date","ServiceFamily","ProductOrderId","ProductOrderName","ConsumedService","MeterId","MeterName","MeterCategory","MeterSubcategory","MeterRegion","ProductId","ProductName","SubscriptionId","SubscriptionName","PublisherType","PublisherId","PublisherName","ResourceGroup","ResourceId","ResourceLocation","ResourceLocationNormalized","EffectivePrice","Quantity","UnitOfMeasure","ChargeType","BillingCurrencyCode","PricingCurrencyCode","CostInBillingCurrency","CostInPricingCurrency","CostInUSD","PaygCostInBillingCurrency","PaygCostInUSD","ExchangeRate","ExchangeRateDate","IsAzureCreditEligible","ServiceInfo1","ServiceInfo2","AdditionalInfo","Tags","PayGPrice","Frequency","Term","ReservationId","ReservationName","PricingModel","UnitPrice","CostAllocationRuleName","BenefitId","BenefitName","Provider"
                            //    },
                            
                        },
                        ExportType = ExportType.ActualCost,
                        Timeframe = TimeframeType.MonthToDate
                    },
    
    0 comments No comments

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.