Hello,
I am experiencing a critical and persistent '401 Unauthorized' error when attempting to access the OneNote API via the Microsoft Graph PowerShell SDK for my personal Microsoft account (MSA). This issue has already undergone extensive, detailed troubleshooting with Microsoft Support agents who were unable to assist, and I am now seeking assistance from this community.
My personal OneNote (onenote.com and desktop app) is functioning perfectly and syncing flawlessly, confirming no general account or sync issues.
Core Problem:
Despite Connect-MgGraph reporting 'Successfully connected to Microsoft Graph' and using the correct authentication flow for personal accounts (including -TenantId "consumers"), all subsequent API calls to https://graph.microsoft.com/v1.0/me/onenote/notebooks consistently return a '401 Unauthorized' error. This behavior contradicts Microsoft Graph's own documentation, which explicitly states that the OneNote API supports personal Microsoft accounts with delegated permissions like Notes.ReadWrite.All.
Key Troubleshooting Performed (All confirmed successful - this is NOT a basic issue):
- Successful Authentication:
Connect-MgGraph
completes without error, and a browser prompt for consent appears and is accepted for Notes.ReadWrite.All
scopes.
- Correct Tenant ID for MSA: Explicitly used
-TenantId "consumers"
with Connect-MgGraph
to ensure authentication targets the personal account identity platform.
- Comprehensive Cache Clearing: Multiple times, I have cleared all cached authentication tokens and data from
%LOCALAPPDATA%\Microsoft\OneAuth\accounts
and %LOCALAPPDATA%\Microsoft\TokenBroker\Cache
to ensure fresh token acquisition.
- OneNote Account Health Verified: Confirmed full, bidirectional sync of OneNote notebooks between the desktop application and onenote.com for my personal Microsoft account. OneDrive sync for general files is also fully functional.
- Diagnostic Scope Testing: Even testing with the less permissive
Notes.Read
scope resulted in the same 401 Unauthorized error.
- Time Elapsed: Waited significant periods between troubleshooting steps to account for any propagation delays.
This problem is not a script error, module installation issue, or a general incompatibility. It strongly indicates a service-side token validation issue specific to my personal Microsoft account and its interaction with the Microsoft Graph OneNote API.
Reproducible Code (Simplified Snippet):
# Ensure Microsoft.Graph.Authentication and Microsoft.Graph.Notes are installed
# Install-Module -Name Microsoft.Graph.Authentication, Microsoft.Graph.Notes -Scope CurrentUser -Force
# Connect to Graph for personal account
Connect-MgGraph -Scopes "Notes.ReadWrite.All" -ContextScope Process -TenantId "consumers"
# After successful connection, retrieve Access Token
$AccessToken = (Get-MgContext).AccessToken
# Attempt to list notebooks (this consistently fails with 401)
$Headers = @{ "Authorization" = "Bearer $AccessToken" }
$Uri = "https://graph.microsoft.com/v1.0/me/onenote/notebooks"
try {
Invoke-RestMethod -Method Get -Uri $Uri -Headers $Headers -Body {} -ContentType "application/json" -ErrorAction Stop
}
catch {
Write-Host "Error accessing OneNote API: $($_.Exception.Message)"
# Note: Full Response may contain sensitive details, consider sanitizing if copy-pasting from a real log
Write-Host "Full Response (if available): $($_.Exception.Response.Content)"
}
Any insights or assistance from the community or Microsoft engineers would be greatly appreciated.