Please note to this doc: Azure consumption API overview , here shows that you can use Usage Details API with filter to get what you want:
- Filtering - Trim your API result set down to a smaller set of usage detail records using the following filters:
- Usage end / usage start
- Resource Group
- Resource Name
Here is the format of this API:
GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?$expand={$expand}&$filter={$filter}&$skiptoken={$skiptoken}&$top={$top}&$apply={$apply}&api-version=2019-01-01
For {scope}
, except can use '/subscriptions/{subscriptionId}/' for subscription scope, it can also use '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope and etc. For more details, reference this doc.
Use $filter={$filter}
can achieve what you want(access specific resource), here provided my API can for your reference:
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/usageDetails?$expand=meterDetails,additionalProperties&$filter=properties/usageEnd ge '2019-01-1' AND properties/usageEnd le '2019-05-22' AND properties/instanceName eq '{instanceName}'&$top=30&api-version=2019-01-01
eq
means equals, ge
means greater or equal, le
means less or
equal, and the instanceNmae means your specific resource name that the usage is about.