Credentials
You need two things: an access token, and (for app-only tokens or SharePoint) a drive ID. Pick whichever token path fits.Option A: Quick token (Graph Explorer)
Fastest way to try it. The token lasts about an hour, which is plenty for a test run.- Open Graph Explorer and Sign in.
- Run any query (for example
GET /me/drive) and consent when prompted. - Open the Access token tab and copy the token.
/me/drive and you do
not need a drive ID.
Option B: Repeatable token (app registration + device code)
Use this for scripted or CI runs.- In the Microsoft Entra admin center, go to Identity -> Applications -> App registrations -> New registration. For a personal account, choose Accounts in any organizational directory and personal Microsoft accounts.
- Under Authentication -> Advanced settings, set Allow public client flows to Yes.
- Under API permissions -> Microsoft Graph -> Delegated, add
Files.ReadWrite.All(addSites.ReadWrite.Allfor SharePoint libraries). - Run the device-code flow with your Application (client) ID:
App-only tokens (client-credentials flow) have no signed-in user, so
/me/drive returns an error. With an app-only token you must pass a
drive_id (or site_id). Delegated tokens (Options A and B) can use /me/drive
with no drive ID.Get your drive ID
Only needed for app-only tokens or to target a specific SharePoint library. With your token exported asTOKEN:
b!a1B2c3....
Set environment variables
Snapshots and version pinning rely on OneDrive/SharePoint version history,
which is on by default. Older versions are only readable while the library
retains them (the version cap is configurable, and an admin can disable
versioning).