Help: I want to obtain billing information through Microsoft Cloud's API,Azure cost management API, but I failed to call it

王帅 0 Reputation points
2024-02-07T07:23:13.91+00:00

my code: ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder() .clientId("my clientId") .clientSecret("my clientSecret") .tenantId("my tenantId") .build(); AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); CostManagementManager manager = CostManagementManager .authenticate(clientSecretCredential, profile); CostDetailsOperationResults operation = manager.generateCostDetailsReports().createOperation("/providers/Microsoft.Billing/billingAccounts/billingAccountId", new GenerateCostDetailsReportRequestDefinition() .withMetric(CostDetailsMetricType.ACTUAL_COST) .withTimePeriod(new CostDetailsTimePeriod().withStart("2023-03-01").withEnd("2023-03-15")), Context.NONE); but i get fail error meesage :
Status code 401, "{"error":{"code":"401","message":"No claims present for the caller in the system"}}": No claims present for the caller in the system

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

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,901 Reputation points
    2024-02-12T08:32:33.2166667+00:00

    @王帅 Thanks for reaching out. The error message "No claims present for the caller in the system" typically indicates an issue with authentication or authorization in an Azure service.

    This error message means that the user or application that is making the request does not have the necessary claims or permissions to access the requested resource. Claims are pieces of information that are used to identify and authenticate users and applications in Azure.

    Kindly check if the service principal that you are using have necessary permissions to access the Cost Management API. For list of permissions related to Cost Management API, refer this document.

    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.