Maton

OneDrive

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/drive
maton one-drive whoami

List User's Drives

GET /one-drive/v1.0/me/drives
maton one-drive drive list

Get 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/root
maton one-drive item view root

List Root Children

GET /one-drive/v1.0/me/drive/root/children
maton one-drive item list

Get 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.pdf
maton one-drive item view-by-path Documents/report.pdf

List Folder Children by Path

GET /one-drive/v1.0/me/drive/root:/Documents:/children
maton one-drive item list Documents

Get Item Children

GET /one-drive/v1.0/me/drive/items/{item-id}/children
maton one-drive item view {item-id} --expand children

Special 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/approot
maton one-drive item view --special documents

Get Recent Files

GET /one-drive/v1.0/me/drive/recent
maton one-drive drive recent

Get Files Shared With Me

GET /one-drive/v1.0/me/drive/sharedWithMe
maton one-drive drive shared
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 Documents

Create 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.pdf

Upload 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 rename

Files 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.txt

Move 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.txt

Returns 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.

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 anonymous

Link types:

  • view - Read-only access
  • edit - Read-write access
  • embed - Embeddable link

Scopes:

  • anonymous - Anyone with the link
  • organization - 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!'

Resources

On this page