How to Collect SharePoint Audit Logs | Office 365 Management API
3 minute read
Overview
SharePoint and OneDrive audit logs capture file operations, sharing activities, and site management actions in your Microsoft 365 environment. Use this guide to monitor document access, track file sharing, detect data exfiltration, and maintain compliance records for file operations.
Common Use Cases:
- Track file access, downloads, and modifications
- Monitor external and internal sharing activities
- Detect potential data exfiltration (bulk downloads)
- Audit site permission changes
- Maintain compliance records for document access
Prerequisites
Before configuring Edge Delta, complete the Office 365 Management API setup:
- Enable unified audit logging in Microsoft Purview compliance portal
- Register an Azure AD application with Office 365 Management APIs permissions
- Grant the
ActivityFeed.Readpermission and obtain admin consent - Start the Audit.SharePoint subscription (one-time setup)
For detailed setup instructions, see Office 365 Management API Integration.
Start SharePoint Subscription
Run this command once to enable SharePoint audit log collection:
# Get OAuth token
TOKEN=$(curl -X POST "https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token" \
-d "client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&scope=https://manage.office.com/.default&grant_type=client_credentials" \
| jq -r '.access_token')
# Start SharePoint subscription
curl -X POST "https://manage.office.com/api/v1.0/{TENANT_ID}/activity/feed/subscriptions/start?contentType=Audit.SharePoint&PublisherIdentifier={TENANT_ID}" \
-H "Authorization: Bearer ${TOKEN}"
Configuration
Basic SharePoint Audit Collection
nodes:
- name: sharepoint_audit_logs
type: http_pull_input
endpoint: https://manage.office.com/api/v1.0/YOUR_TENANT_ID/activity/feed/subscriptions/content
method: GET
pull_interval: 5m
authorization:
strategy: oauth_client_credentials
client_credentials:
token_url: https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token
client_id: YOUR_CLIENT_ID
client_secret: YOUR_CLIENT_SECRET
scopes:
- https://manage.office.com/.default
header_templates:
- header: Authorization
value: Bearer $ACCESS_TOKEN
parameters:
- name: contentType
value: Audit.SharePoint
- name: PublisherIdentifier
value: YOUR_TENANT_ID
parameter_expressions:
- name: startTime
value_expression: FormatTime(Now() - Duration("6m"), "%Y-%m-%dT%H:%M:%SZ")
- name: endTime
value_expression: FormatTime(Now() - Duration("1m"), "%Y-%m-%dT%H:%M:%SZ")
pagination:
url_json_path: contentUri
response_format: json
max_parallel: 3
inherit_auth: true
error_strategy: continue
SharePoint Audit Operations
File Operations
| Operation | Description |
|---|---|
FileAccessed | File opened or viewed |
FileDownloaded | File downloaded to local device |
FileUploaded | File uploaded to SharePoint/OneDrive |
FileModified | File content changed |
FileDeleted | File deleted |
FileRestored | File restored from recycle bin |
FileMoved | File moved to new location |
FileCopied | File copied |
FileRenamed | File renamed |
Sharing Operations
| Operation | Description |
|---|---|
SharingSet | Sharing permissions configured |
SharingInvitationCreated | Sharing invitation sent |
SharingInvitationAccepted | Sharing invitation accepted |
AnonymousLinkCreated | Anyone link created |
CompanyLinkCreated | Organization-wide link created |
SharingRevoked | Sharing permissions removed |
Site Operations
| Operation | Description |
|---|---|
SiteCollectionCreated | New site collection created |
SiteDeleted | Site deleted |
GroupAdded | Group added to site |
PermissionLevelAdded | Permission level created |
Sample SharePoint Audit Log
{
"CreationTime": "2024-01-01T10:05:00",
"Id": "sharepoint-audit-guid",
"Operation": "FileDownloaded",
"OrganizationId": "org-guid",
"RecordType": 6,
"UserType": 0,
"Workload": "SharePoint",
"UserId": "user@company.com",
"ClientIP": "192.168.1.100",
"ObjectId": "https://company.sharepoint.com/sites/team/Documents/confidential-report.docx",
"SourceFileName": "confidential-report.docx",
"SourceFileExtension": "docx",
"SourceRelativeUrl": "sites/team/Documents",
"SiteUrl": "https://company.sharepoint.com/sites/team",
"ItemType": "File",
"UserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0",
"Platform": "Windows 10"
}
Key Fields for Analysis
| Field | Description | Use Case |
|---|---|---|
Operation | Action performed | Identify activity type |
UserId | Who performed the action | Attribute activity to user |
ObjectId | Full path to file | Identify target document |
SourceFileName | File name | Quick file identification |
SiteUrl | SharePoint site | Identify site context |
ClientIP | Source IP address | Detect anomalous access |
ItemType | File, Folder, Site, etc. | Filter by item type |
High-Value Operations to Monitor
| Operation | Risk Level | Description |
|---|---|---|
AnonymousLinkCreated | High | Public sharing link created |
FileDownloaded (bulk) | High | Potential data exfiltration |
SharingSet (external) | Medium | External sharing enabled |
FileDeleted (sensitive) | Medium | Sensitive file deletion |
PermissionLevelAdded | Medium | Permission escalation |
Detecting Bulk Downloads
Monitor for potential data exfiltration by tracking multiple downloads:
# Use downstream processing to detect:
# - Same user downloading many files in short period
# - Downloads from unusual IP addresses
# - Downloads outside business hours
Key fields to aggregate:
UserId+Operation: FileDownloaded- Count per 15-minute window
- Alert if count exceeds threshold (e.g., 50 files)
Troubleshooting
| Issue | Solution |
|---|---|
| Empty results | Verify Audit.SharePoint subscription is started |
| 401 Unauthorized | Check client credentials and tenant ID |
| 403 Forbidden | Ensure ActivityFeed.Read permission has admin consent |
| OneDrive missing | OneDrive events are included in Audit.SharePoint |
Related Pages
- Office 365 Management API Overview - Complete API reference
- Exchange Audit Logs - Email monitoring
- Teams Audit Logs - Teams activity monitoring