Hello @procomix Thank you for reaching out to us on Microsoft Q&A platform. Happy to help!
I see that you want to get the cost of the subscription using REST API's. You can fetch subscription cost using Azure Cost Management API, you can use the following API endpoint:
GET https://<span class=" active-doc-0 active-doc-1 active-doc-4" data-doc-items="0,1,4">management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2019-11-01&$top=100&$skip=0[1](#doc-pos=0)[2](#doc-pos=1)[3](#doc-pos=4)</span>
Here, you need to replace {scope}
with the scope of your subscription, such as /subscriptions/{subscriptionID}
. You can also add filters to the query to retrieve specific data**4**.
For example, to retrieve the cost of a subscription for the last month, you can use the following query:
POST https://<span class=" active-doc-0 active-doc-1 active-doc-4" data-doc-items="0,1,4">management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2019-11-01[1](#doc-pos=0)[2](#doc-pos=1)[3](#doc-pos=4)</span>
{
"type": "Usage",
"timeframe": "MonthToDate",
"dataset": {
"granularity": "Daily",
"aggregation": {
"totalCost": {
"name": "PreTaxCost",
"function": "Sum"
}
},
"grouping": [
{
"type": "Dimension",
"name": "ResourceId"
}
]
}
}
This will return the total cost of the subscription for the current month, grouped by resource ID. You can modify the query to retrieve data for a different timeframe or to group the data differently.
Hope this helps. Please tag me in your reply if you need further assistance!
If the response helped, do "Accept Answer" and up-vote it