Microsoft Graph OneDrive & Office Insights API Deprecations: Migrate /drive/recent, /sharedWithMe & /insights Endpoints

Enterprise automation engineers and intranet developers building on Microsoft Graph face a critical set of API retirements across OneDrive for Business, SharePoint Online, and Office Graph Insights. As Microsoft consolidates file discovery and activity intelligence around the unified Microsoft Search API (/search/query) and Microsoft 365 Copilot Semantic Index, several long-standing v1.0 and beta endpoints are being retired:

  • GET /me/drive/recent and GET /drives/{id}/recent (Deprecated in favor of Microsoft Search & Activity queries)
  • GET /me/drive/sharedWithMe (Deprecated due to cross-tenant B2B and permission enumeration changes)
  • GET /me/insights/used, GET /me/insights/shared, and GET /me/insights/trending (Sites.Read.All Office Graph Insights retirement)

When these endpoints reach hard retirement, scheduled PowerShell reporting scripts, custom SharePoint Framework (SPFx) web parts, and governance bots calling them will fail with 404 Not Found or 410 Gone HTTP responses.

In this migration runbook, we provide the exact replacement architectures for each deprecated endpoint, show how to rewrite your Microsoft Graph PowerShell SDK scripts using Invoke-MgGraphRequest and /search/query, and audit your Entra ID Service Principals for legacy API dependencies.


Deprecated Microsoft Graph File & Insights Endpoints vs. Modern Replacements

Deprecated Graph EndpointLegacy Use CaseModern Replacement EndpointRequired Permission Scope
GET /me/drive/recentList files recently opened or modified by a userPOST /v1.0/search/query (entityTypes: ["driveItem"] sorted by lastModifiedDateTime)Files.Read.All
GET /me/drive/sharedWithMeList files shared with the user by internal or external collaboratorsPOST /v1.0/search/query with KQL filter (SharedWithUsersOWSUSER or ViewableByExternalUsers)Files.Read.All, Sites.Read.All
GET /users/{id}/insights/usedAudit documents recently viewed or modified by a userUnified Audit Log (Search-UnifiedAuditLog -Operations FileAccessed,FileModified) or /search/queryAuditLogsQuery.Read.All / Files.Read.All
GET /users/{id}/insights/sharedAudit files shared with or by a userGET /drives/{id}/root/delta + GET /drives/{id}/items/{id}/permissionsFiles.Read.All, Sites.Read.All
Microsoft Graph API Migration: Legacy Drive & Insights vs. Microsoft Search & Delta APIs Retiring Graph Endpoints (404 / 410 Gone) ✖ GET /v1.0/me/drive/recent - Legacy OneDrive MRU list; inconsistent across SPO sites ✖ GET /v1.0/me/drive/sharedWithMe - Retiring `Get-MgDriveSharedWithMe` cmdlet ✖ GET /v1.0/users/{id}/insights/used & /shared - Retiring `Get-MgUserInsightUsed` / `Get-MgUserInsightShared` Impact: Breaks SPFx web parts & governance scripts Modern Supported Graph Architecture ✔ POST /v1.0/search/query (entityTypes: driveItem) - KQL-powered query across OneDrive & SharePoint ✔ GET /v1.0/drives/{id}/root/delta - High-speed incremental file & sharing state sync ✔ GET /v1.0/drives/{id}/items/{id}/permissions - Exact sharing links (`anonymous`, `organization`, `users`) Benefit: Unified Copilot & Search index compatibility PowerShell Cmdlets to Replace Immediately: • Search your Git repositories for `Get-MgDriveRecent`, `Get-MgDriveSharedWithMe`, `Get-MgUserInsightUsed`, and `Get-MgUserInsightShared`. • Replace them with `Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/search/query"` or `/drives/{id}/root/delta`.

Migration Pattern 1: Replace GET /me/drive/recent and /insights/used with Microsoft Search API (/v1.0/search/query)

Previously, scripts called Get-MgDriveRecent (GET /drives/{id}/recent) or Get-MgUserInsightUsed (GET /users/{id}/insights/used) to list recently modified or accessed files.

The modern replacement uses the Microsoft Search API (POST /v1.0/search/query) querying driveItem entities with Keyword Query Language (KQL) and sorting by lastModifiedDateTime:

POWERSHELL
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Files.Read.All", "Sites.Read.All" -NoWelcome

# Modern Replacement for /drive/recent & /insights/used using Microsoft Search API
$SearchPayload = @{
    requests = @(
        @{
            entityTypes = @("driveItem")
            query       = @{
                # KQL: Find documents modified in the last 30 days
                queryString = "LastModifiedTime>=$( (Get-Date).AddDays(-30).ToString('yyyy-MM-dd') ) AND IsDocument:true"
            }
            from        = 0
            size        = 25
            fields      = @(
                "name",
                "webUrl",
                "lastModifiedDateTime",
                "lastModifiedBy",
                "size"
            )
            sortProperties = @(
                @{
                    name         = "lastModifiedDateTime"
                    isDescending = $true
                }
            )
        }
    )
} | ConvertTo-Json -Depth 6

$Response = Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/search/query" -Body $SearchPayload
$Hits = $Response.value[0].hitsContainers[0].hits

$RecentFiles = foreach ($Hit in $Hits) {
    [PSCustomObject]@{
        FileName     = $Hit.resource.name
        LastModified = $Hit.resource.lastModifiedDateTime
        ModifiedBy   = $Hit.resource.lastModifiedBy.user.displayName
        WebUrl       = $Hit.resource.webUrl
    }
}

$RecentFiles | Format-Table -AutoSize

Migration Pattern 2: Replace /drive/sharedWithMe and /insights/shared for External Sharing Audits

Many security teams previously misused /users/{id}/insights/shared or /drive/sharedWithMe to audit external file sharing across OneDrive and SharePoint Online. That approach was both incomplete (it only returned algorithmically ranked items) and is now deprecated.

To perform a complete, deterministic audit of shared files on a user's OneDrive or SharePoint site in 2026 using App-Only Certificate Authentication, query the user's OneDrive (GET /users/{id}/drive) and enumerate items via /root/delta and /permissions:

POWERSHELL
# Unattended Certificate-Based App-Only Connection (Works in Scheduled Tasks)
$TenantId       = "ab85c7a1-366d-44ba-acc6-924fa0950045"
$ClientId       = "c841ae33-4093-4385-8a90-6a530761f9b9"
$CertThumbprint = "BEAC429DE404B46FF030811C0C9DE00DE701C027"

Connect-MgGraph -TenantId $TenantId -ClientId $ClientId -CertificateThumbprint $CertThumbprint -NoWelcome

$TargetUserUPN = "[email protected]"

# 1. Resolve the User's OneDrive ID
$Drive = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/users/$TargetUserUPN/drive"
Write-Host "[+] Auditing OneDrive for $TargetUserUPN (DriveId: $($Drive.id))" -ForegroundColor Cyan

# 2. Query Drive Items via Delta API (Replaces /insights/shared)
$DeltaItems = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($Drive.id)/root/delta?`$select=id,name,webUrl,shared,file").value

# 3. Filter Only Items That Have Active Sharing Permissions
$SharedItems = $DeltaItems | Where-Object { $null -ne $_.shared }

$SharingReport = foreach ($Item in $SharedItems) {
    $Perms = (Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($Drive.id)/items/$($Item.id)/permissions").value
    foreach ($p in $Perms) {
        if ($p.link -or $p.grantedToV2) {
            [PSCustomObject]@{
                ItemName  = $Item.name
                LinkScope = if ($p.link) { $p.link.scope } else { "DirectGrant" }
                LinkType  = if ($p.link) { $p.link.type } else { ($p.roles -join ",") }
                GrantedTo = $p.grantedToV2.user.email
                WebUrl    = $Item.webUrl
            }
        }
    }
}

$SharingReport | Format-Table -AutoSize

Step 3: Scan Your Local PowerShell & Automation Repository for Deprecated Cmdlets

Run the following PowerShell one-liner across your automation server or Git repositories to flag any scripts calling the retiring OneDrive or Office Graph Insights endpoints before they fail in production:

POWERSHELL
# Scan all .ps1, .js, .ts, and .cs files for deprecated Graph endpoints and SDK cmdlets
$DeprecatedPatterns = @(
    "Get-MgDriveRecent",
    "Get-MgDriveSharedWithMe",
    "Get-MgUserInsightUsed",
    "Get-MgUserInsightShared",
    "Get-MgUserInsightTrending",
    "/drive/recent",
    "/drive/sharedWithMe",
    "/insights/used",
    "/insights/shared",
    "/insights/trending"
)

$Regex = ($DeprecatedPatterns | ForEach-Object { [regex]::Escape($_) }) -join "|"

Get-ChildItem -Path "C:\Scripts" -Recurse -Include *.ps1,*.psm1,*.js,*.ts,*.cs |
    Select-String -Pattern $Regex |
    Select-Object Path, LineNumber, Line |
    Format-Table -AutoSize

Key Takeaways for Microsoft 365 Developers & Admins

  1. Standardize on /v1.0/search/query for User-Centric File Discovery: The Microsoft Search API respects SharePoint and OneDrive ACLs automatically and is the same search fabric powering Microsoft 365 Copilot.
  2. Use /drives/{id}/root/delta for Security & Sharing Audits: Never rely on /insights/shared for compliance reporting; delta + /permissions guarantees 100% coverage of anonymous links, organization links, and external B2B guest grants.