|
| 1 | +--- |
| 2 | +title: Retrieve activity log data using Azure monitor REST API |
| 3 | +description: How to retrieve activity log data using Azure monitor REST API. |
| 4 | +author: EdB-MSFT |
| 5 | +ms.topic: conceptual |
| 6 | +ms.date: 03/10/2024 |
| 7 | +ms.reviewer: priyamishra |
| 8 | + |
| 9 | +# customer intent: As a developer, I want to learn how to retrieve activity log data using Azure monitor REST API. |
| 10 | +--- |
| 11 | + |
| 12 | +# Retrieve activity log data using Azure monitor REST API |
| 13 | + |
| 14 | +The Azure Activity Log is a log that provides insight into operations performed on resources in your subscription. Operations include create, update, delete, and other actions taken on resources. The Activity Log is a platform-wide log and isn't limited to a particular service. This article explains how to retrieve activity log data using the Azure Monitor REST API. For more information about the activity log, see [Azure Activity Log event schema](/azure/azure-monitor/essentials/activity-log-schema). |
| 15 | + |
| 16 | + |
| 17 | +## Authentication |
| 18 | + |
| 19 | +To retrieve resource logs, you must authenticate with Microsoft Entra. For more information, see [Azure monitoring REST API walkthrough](/azure/azure-monitor/essentials/rest-api-walkthrough?tabs=powershell#authenticate-azure-monitor-requests). |
| 20 | + |
| 21 | +## Retrieve activity log data |
| 22 | + |
| 23 | +Use the Azure Monitor REST API to query [activity log](/rest/api/monitor/activitylogs) data. |
| 24 | + |
| 25 | +The following request format is used to request activity log data. |
| 26 | + |
| 27 | +```curl |
| 28 | +GET /subscriptions/<subscriptionId>/providers/Microsoft.Insights/eventtypes/management/values \ |
| 29 | +?api-version=2015-04-01 \ |
| 30 | +&$filter=<filter> \ |
| 31 | +&$select=<select> |
| 32 | +host: management.azure.com |
| 33 | +authorization: Bearer <token> |
| 34 | +``` |
| 35 | + |
| 36 | +### $filter |
| 37 | +`$filter` reduces the set of data collected. This argument is required and it also requires at least the start date/time. |
| 38 | +The `$filter` argument accepts the following patterns: |
| 39 | +- List events for a resource group: `$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceGroupName eq <resourceGroupName>`. |
| 40 | +- List events for a specific resource: `$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceUri eq <resourceURI>`. |
| 41 | +- List events for a subscription in a time range: `$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z'`. |
| 42 | +- List events for a resource provider: `$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and resourceProvider eq <resourceProviderName>`. |
| 43 | +- List events for a correlation ID:` $filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and correlationId eq '<correlationID>`. |
| 44 | + |
| 45 | + |
| 46 | +### $select |
| 47 | +`$select` fetches a specified list of properties for the returned events. |
| 48 | +The `$select` argument is a comma separated list of property names to be returned. |
| 49 | +Valid values are: |
| 50 | +`authorization`, `claims`, `correlationId`, `description`, `eventDataId`, `eventName`, `eventTimestamp`, `httpRequest`, `level`, `operationId`, `operationName`, `properties`, `resourceGroupName`, `resourceProviderName`, `resourceId`, `status`, `submissionTimestamp`, `subStatus`, and `subscriptionId`. |
| 51 | + |
| 52 | +The following sample requests use the Azure Monitor REST API to query an activity log. |
| 53 | +### Get activity logs with filter: |
| 54 | + |
| 55 | +The following example gets the activity logs for resource group `MSSupportGroup` between the dates `2023-03-21T20:00:00Z` and `2023-03-24T20:00:00Z` |
| 56 | + |
| 57 | +``` HTTP |
| 58 | +GET https://management.azure.com/subscriptions/12345678-abcd-98765432-abcdef012345/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2023-03-21T20:00:00Z' and eventTimestamp le '2023-03-24T20:00:00Z' and resourceGroupName eq 'MSSupportGroup' |
| 59 | +``` |
| 60 | +### Get activity logs with filter and select: |
| 61 | + |
| 62 | +The following example gets the activity logs for resource group `MSSupportGroup`, between the dates `2023-03-21T20:00:00Z` and `2023-03-24T20:00:00Z`, returning the elements eventName, operationName, status, eventTimestamp, correlationId, submissionTimestamp, and level. |
| 63 | + |
| 64 | +```HTTP |
| 65 | +GET https://management.azure.com/subscriptions/12345678-abcd-98765432-abcdef012345/providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&$filter=eventTimestamp ge '2023-03-21T20:00:00Z' and eventTimestamp le '2023-03-24T20:00:00Z'and resourceGroupName eq 'MSSupportGroup'&$select=eventName,operationName,status,eventTimestamp,correlationId,submissionTimestamp,level |
| 66 | +``` |
| 67 | + |
| 68 | +## Next steps |
| 69 | +[Stream Azure Monitor activity log data](azure/azure-monitor/essentials/activity-log). |
| 70 | +[Azure Activity Log event schema](/azure/azure-monitor/essentials/activity-log-schema). |
| 71 | + |
0 commit comments