Automation for partners

Azure Cost Management is natively available for direct partners who have onboarded their customers to a Microsoft Customer Agreement and have purchased an Azure Plan. Partners and their customers can use Cost Management APIs common tasks. For more information about non-automation scenarios, see Cost Management for Partners.

Azure Cost Management APIs - Direct and indirect providers

Partners with access to billing scopes in a partner tenant can use the following APIs to view invoiced costs.

APIs at the subscription scope can be called by a partner regardless of the cost policy, as long as they have access to the subscription. Other users with access to the subscription, like the customer or reseller, can call the APIs only after the partner enables the cost policy for the customer tenant.

To get a list of billing accounts

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts?api-version=2019-10-01-preview 

To get a list of customers

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/customers?api-version=2019-10-01-preview 

To get a list of subscriptions

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingSubscriptions?api-version=2019-10-01-preview 

To get a list of invoices for a period of time

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoices?api-version=2019-10-01-preview&periodStartDate={periodStartDate}&periodEndDate={periodEndDate} 

The API call returns an array of invoices that has elements similar to the following JSON code.

   {      "id": "/providers/Microsoft.Billing/billingAccounts/{billingAccountID}/billingProfiles/{BillingProfileID}/invoices/{InvoiceID}",      "name": "{InvoiceID}",      "properties": {        "amountDue": {          "currency": "USD",          "value": x.xx        },        ...    } 

Use the preceding returned ID field value and replace it in the following example as the scope to query for usage details.

GET https://management.azure.com/{id}/providers/Microsoft.Consumption/UsageDetails?api-version=2019-10-01 

The example returns the usage records associated with the specific invoice.

To get the policy for customers to view costs

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/customers/{customerID}/policies/default?api-version=2019-10-01-preview 

To set the policy for customers to view costs

PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/customers/{customerID}/policies/default?api-version=2019-10-01-preview 

To get Azure service usage for a billing account

We recommend that you configure an Export for these scenarios. For more information, see Retrieve large usage datasets with exports.

To download a customer's Azure service usage

We recommend that you configure an Export for this scenario as well. If you need to download the data on demand, however, you can use the Cost Details API. For more information, see Get small cost datasets on demand.

To get or download the price sheet for consumed Azure services

First, use the following post.

POST https://management.azure.com/providers/Microsoft.Billing/BillingAccounts/{billingAccountName}/billingProfiles/{billingProfileID}/pricesheet/default/download?api-version=2019-10-01-preview&format=csv" -verbose 

Then, call the asynchronous operation property value. For example:

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileID}/pricesheetDownloadOperations/{operation}?sessiontoken=0:11186&api-version=2019-10-01-preview 

The preceding get call returns the download link containing the price sheet.

To get aggregated costs

POST https://management.azure.com/providers/microsoft.billing/billingAccounts/{billingAccountName}/providers/microsoft.costmanagement/query?api-version=2019-10-01 

Create a budget for a partner

PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/providers/Microsoft.CostManagement/budgets/partnerworkshopbudget?api-version=2019-10-01 

Create a budget for a customer

PUT https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/customers/{customerID}/providers/Microsoft.Consumption/budgets/{budgetName}?api-version=2019-10-01 

Delete a budget

DELETE https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.CostManagement/budgets/{budgetName}?api-version=2019-10-01 

Next steps