get azure subscription belongs to what type for example Pay As you Go, MCA, EA, CSP - azure

I tried to fetch azure subscription belongs to what type for example Pay As you Go, MCA, EA, CSP by using REST API But I am not able to find the appropriate API for this case.
I used Consumption Usage Details API, from this API response I am getting kind as Legacy or Modern
Is there any Rest API for this?

It's not possible to get the Offer Types from any API's, But you can get the offerId from the Consumption Usage Details API.
So, After you get offerId (for example "offerId" : "MS-AZR-0003P") , then you can take just the offerId number (i.e. 0003P). And refer it here to check what type of Offer it is (in this case its Pay-As-You-Go).

Related

az rest command to get Usage Details for previous months/dates. (Microsoft.Consumption)

I have the following URL which is used to get the UsageDetails from Microsoft. consumption
az rest --method GET --url 'https://management.azure.com/subscriptions/{subscription}/providers/Microsoft.Consumption/UsageDetails?api-version=2019-10-01'
Now, I want the details for the time periods between 2022-11-01 and 2022-11-30. But so far I have been only able to retrieve current billing cycle details.
Please let me know if I have to use a different API version or how to add the date/timeframe filter to the API call to retrieve the previous month's data other than the current billing cycle.
Also, I am open to suggestions if there is a different command call altogether to get these cost/ usage of resources/subscriptions other than az rest with Microsoft.Consumption
There are two different methods of filtering usage details: one works only for legacy subscriptions and another for modern subscriptions.
For legacy customers with an Enterprise Agreement (EA) or a pay-as-you-go subscription, use the parameter $filter=properties/usageStart ge '2022-11-01' and properties/usageEnd le '2022-11-30'. So the API request should look like this:
GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?$filter=properties%2FusageStart%20ge%20'2022-11-01'%20and%20properties%2FusageEnd%20le%20'2022-11-30'&$top=1000&api-version=2019-10-01
For modern customers with a Microsoft Customer Agreement, use the parameters startDate and endDate, for example:
GET https://management.azure.com/{scope}/providers/Microsoft.Consumption/usageDetails?startDate=2022-11-01&endDate=2022-11-30&$top=1000&api-version=2019-10-01
See documentation for more details. Please note that the data returned by the API corresponds to the date when the usage was received by the billing system and it can include costs from multiple invoices.

Azure Api Management log user accessed api

Is there any rest api that can be used to fetch api access detail for a user. To know how many times a user accessed a api and how many success or failure request were there. i am not able to use log-to-eventhub.
Thanks to #MayankBargali-MSFT's Q&A answer to similar kind of issue and posting here to help other community members!
Azure APIM will do monitor the APIs published but only listed details are logged as per the APIManagementGatewayLogs.
Based on your requirement, leveage the APIM reporting API and refer to Microsoft Doc for more information on reporting API.
To know who the user accessed particular API in APIM recently, You can call the List by Request API by adding the filter (For example, last 4 days from this day, apiID, etc.).
The above response will provide the details like apiID, timeStamp, userID that helps to find the details.
Still paraphrasing #MayankBargali-MSFT from the post linked above:
To know how many time that user accessed the API, use List by User API where it gives the overall result in which we need to filter with the apiID, then you can get the API Level count.
Point to note here is:
Filter might not work for every column. Therefore, you must modify the outcome at your client's end to perform more filtering and obtain the appropriate result. For further information, kindly consult the relevant API document. As long as you don't delete the APIM instance, the data will continue to be maintained permanently.

Not able to get Azure Billing Account Id

I need to get Usage Details at Billing Account Scope for that firstly I used this API but It returns an empty value. I used the Bearer Access token for hitting this API.Is anything other than this am I missed?
Postman Request attached as screenshot
I believe you're using the wrong API. To get Billing info you must provide billing account name:
GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}?api-version=2019-10-01-preview
https://learn.microsoft.com/en-us/rest/api/billing/2019-10-01-preview/billingaccounts/get
PS: you can use the "try it" and test if it will return the information you need.
You can also query usage API and use one of the available dimensions to get cost related info:
POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2019-11-01
https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage
This api will return a value if account belongs to Modern billing

azure billing rate card api returns noting

I am trying to call the Azure billing rate card api. The call is happening successfully after the authentication because the status code is OK. But though I have a vm in the corresponding resource group and subscription, always getting response as:
{"value":[]}
Same is happening in case of azure billing usage api. I had seen one question asked for billing usage api but I have tried all the options mentioned like keep the duration for 3 months, don’t keep future date etc, yet there is no response”:
{"value":[],
nextLink:”https://….”}
Please let me know the issue could be abd because of which both rate card and usage api are not returning right data.
Thanks
You were right, I had the same problem and i resolved it on giving 'reader' persmission on my servie account in my subscription .
Thx a lot !

How to get Azure offer details using the API?

I was trying to query the usage and billing API that Azure recently recently and saw that I can use the following API to get the rate card:
https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Commerce/RateCard?api-version=2015-06-01-preview&$filter=OfferDurableId eq '{offer-id}' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'
However, this requires I need to explicity know the offerDurableId, which I came to know for my case from Azure's website.
Is there an API that will give me these offer codes?
AFAIK, there is no API to get the offer codes. In fact if you look at Billing API documentation here, they also ask you to get the information about this from the link you mentioned.
Set {OfferDurableId} to a valid Offer ID code (e.g., MS-AZR-0026P).
See Microsoft Azure Offer Details for more information on the list of
available Offer IDs, country/region availability, and billing
currency. The Offer ID parameter consists of the “MS-AZR-“ prefix,
plus the Offer ID number.
Considering the offer code don't change, I think it is somewhat safe to save this information in your own database
One possibility is this. But it's not documented or supported officially. It's the API which the Azure Portal calls to get the offer information.
https://stackoverflow.com/a/54324041/9893001
There is not public API for this, but there is a feature request, please vote for it.

Resources