Access the OneDrive API with managed OAuth authentication via Microsoft Graph. Manage files, folders, drives, and sharing with full CRUD operations.
Reference
Get Current User's Drive
GET /one-drive/v1.0/me/drivematon one-drive whoamiList User's Drives
GET /one-drive/v1.0/me/drivesmaton one-drive drive listGet Drive by ID
GET /one-drive/v1.0/drives/{drive-id}maton one-drive drive view {drive-id}Get Drive Root
GET /one-drive/v1.0/me/drive/rootmaton one-drive item view rootList Root Children
GET /one-drive/v1.0/me/drive/root/childrenmaton one-drive item listGet Item by ID
GET /one-drive/v1.0/me/drive/items/{item-id}maton one-drive item view {item-id}Get Item by Path
Use colon (:) syntax to access items by path:
GET /one-drive/v1.0/me/drive/root:/Documents/report.pdfmaton one-drive item view-by-path Documents/report.pdfList Folder Children by Path
GET /one-drive/v1.0/me/drive/root:/Documents:/childrenmaton one-drive item list DocumentsGet Item Children
GET /one-drive/v1.0/me/drive/items/{item-id}/childrenmaton one-drive item view {item-id} --expand childrenSpecial Folders
Access known folders by name:
GET /one-drive/v1.0/me/drive/special/documents
GET /one-drive/v1.0/me/drive/special/photos
GET /one-drive/v1.0/me/drive/special/music
GET /one-drive/v1.0/me/drive/special/approotmaton one-drive item view --special documentsGet Recent Files
GET /one-drive/v1.0/me/drive/recentmaton one-drive drive recentGet Files Shared With Me
GET /one-drive/v1.0/me/drive/sharedWithMematon one-drive drive sharedSearch
GET /one-drive/v1.0/me/drive/root/search(q='budget')maton one-drive drive search 'budget'Create Folder
POST /one-drive/v1.0/me/drive/root:/Documents:/children
Content-Type: application/json
{
"name": "Reports",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}maton one-drive item create-folder Reports --path DocumentsCreate folder inside another folder by parent ID:
POST /one-drive/v1.0/me/drive/items/{parent-id}/children
Content-Type: application/json
{
"name": "Reports",
"folder": {}
}maton one-drive item create-folder Reports --parent-id {parent-id}Upload File (Simple - up to 4MB)
PUT /one-drive/v1.0/me/drive/root:/Documents/report.pdf:/content
Content-Type: application/pdf
{report.pdf binary content}maton one-drive item upload ./report.pdf --path Documents/report.pdfUpload File (Large - resumable)
For files over 4MB, use resumable upload:
Step 1: Create upload session
POST /one-drive/v1.0/me/drive/root:/large-report.pdf:/createUploadSession
Content-Type: application/json
{
"item": {
"@microsoft.graph.conflictBehavior": "rename"
}
}maton one-drive item upload ./large-report.pdf --path large-report.pdf --conflict renameFiles larger than 4 MiB automatically use a resumable upload session.
Response:
{
"uploadUrl": "https://sn3302.up.1drv.com/up/...",
"expirationDateTime": "2024-02-08T10:00:00Z"
}Step 2: Upload bytes to the uploadUrl
Download File
Get the file metadata to retrieve the download URL:
GET /one-drive/v1.0/me/drive/items/{item-id}maton one-drive item view {item-id}The response includes @microsoft.graph.downloadUrl - a pre-authenticated URL valid for a short time:
{
"id": "...",
"name": "document.pdf",
"@microsoft.graph.downloadUrl": "https://public-sn3302.files.1drv.com/..."
}Use this URL directly to download the file content (no auth header needed).
Update Item (Rename/Move)
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"name": "new-name.txt"
}maton one-drive item update {item-id} --name new-name.txtMove to different folder:
PATCH /one-drive/v1.0/me/drive/items/{item-id}
Content-Type: application/json
{
"parentReference": {
"id": "{new-parent-id}"
}
}maton one-drive item move {item-id} --dest-id {new-parent-id}Copy Item
POST /one-drive/v1.0/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"id": "{destination-folder-id}"
},
"name": "copied-file.txt"
}maton one-drive item copy {item-id} --dest-id {destination-folder-id} --name copied-file.txtReturns 202 Accepted with a Location header to monitor the copy operation.
Delete Item
DELETE /one-drive/v1.0/me/drive/items/{item-id}maton one-drive item delete {item-id}Returns 204 No Content on success.
Create Sharing Link
POST /one-drive/v1.0/me/drive/items/01ABCDEF/createLink
Content-Type: application/json
{
"type": "view",
"scope": "anonymous"
}maton one-drive item share 01ABCDEF --type view --scope anonymousLink types:
view- Read-only accessedit- Read-write accessembed- Embeddable link
Scopes:
anonymous- Anyone with the linkorganization- Anyone in your organization
Invite Users (Share with specific people)
POST /one-drive/v1.0/me/drive/items/{item-id}/invite
Content-Type: application/json
{
"recipients": [
{"email": "user@example.com"}
],
"roles": ["read"],
"sendInvitation": true,
"message": "Check out this file!"
}maton one-drive item invite {item-id} --emails user@example.com --roles read --message 'Check out this file!'