Newbie question, 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 in advance.
CodePudding user response:
You have to connect API Management with App Insights.
What data is added to Application Insights:
Request
For every incoming request:
-frontend request
-frontend response
With the Application Insights REST API you are able to query the requests.
Example:
POST https://api.applicationinsights.io/v1/apps/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/query
Request body:
{
"timespan": "PT12H",
"query": "requests | order by timestamp | where customDimensions.[\"Service Type\"] == \"API Management\" | where customDimensions.[\"Subscription Name\"] == \"5cda19684fb50e13d009cadd\" | where resultCode == \"200\""
}
CodePudding user response:
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.
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.