There’s no switch to enable the Cost Management Export API — it’s available by default for supported Azure accounts. To use it, make sure your subscription type supports it and that your user or service principal has the correct permissions.
🔍 1. Verify Your Subscription Type
The Cost Management API works with the following:
- Enterprise Agreement (EA)
- Microsoft Customer Agreement (MCA)
- Most Pay-As-You-Go accounts under MCA
✅ No action is needed if you’re already using one of these. If you’re on a CSP or legacy offer, check compatibility in the Azure documentation.
⚙️ 2. Register the Resource Provider (If Needed)
This step is usually automatic, but if you get a 401 Unauthorized
error when using cost APIs, check and register the provider.
Check if the provider is registered:
bashCopyEditaz provider show -n Microsoft.CostManagement -o table
Register if it’s not:
bashCopyEditaz provider register -n Microsoft.CostManagement
✅ Result: Your subscription can now access Cost Management APIs.
🔐 3. Ensure You Have Proper Permissions
To use the APIs and export data:
Action | Required Role |
---|---|
View cost data | Reader at the subscription or billing scope |
Create export jobs | Cost Management Contributor or Owner |
Write to storage | Contributor + Storage Blob Data Contributor (directly or via managed identity) |
✅ Result: Your user or service principal has the necessary access to use the API and write export data.
📤 4. Use the Cost Management APIs
- On-demand cost data:
Use theCost Details API
:GET /{scope}/providers/Microsoft.CostManagement/query
- Scheduled exports:
Use theExports API
:POST /{scope}/providers/Microsoft.CostManagement/exports/{exportName}
You can also schedule exports through the Azure Portal or use Power BI, which leverages the same APIs.
🧯 Troubleshooting
- 401 errors? Check if the
Microsoft.CostManagement
provider is registered. - Permission denied? Make sure you have the right RBAC roles at both the subscription and storage account level.
- Export fails to write to Storage? Check if the managed identity has
Storage Blob Data Contributor
.