微算力 · API 导航与自营网关
API 接入 EN
未登录登录
☁️

托管 OAuth 的 OneDrive 全功能 API 网关

Microsoft OneDrive · v1.0.6
开发 安全 A 级 榜单 #46 作者 byungkyu 公开目录收录
7.3k 下载 10 安装 28.8k 收藏 28 浏览

简介

通过 Maton 代理安全调用 Microsoft Graph,实现 OneDrive 文件的 CRUD、分享与搜索,需配置 API Key 与 OAuth 连接

原始描述

OneDrive API integration with managed OAuth via Microsoft Graph. Manage files, folders, and sharing. Use this skill when users want to upload, download, organize, or share files in OneDrive. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires net

通过你的 Agent 添加

安装目录:one-drive/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/microsoft-onedrive/
Codex CLI~/.codex/skills/microsoft-onedrive/
DeepSeek Harness~/.agents/skills/microsoft-onedrive/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

one-drive 是一个纯文档型 Skill,通过 Maton 平台代理调用 Microsoft Graph API,实现 OneDrive 云存储的完整操作。用户需先在 maton.ai 注册获取 MATON_API_KEY,完成 OAuth 授权后即可执行文件管理操作。

主要功能模块:

  • 驱动器管理:获取用户默认 Drive、列举多个 Drive、查看 Drive 元数据
  • 文件/文件夹操作:通过 ID 或路径(:/path: 语法)访问项目、创建文件夹、列出子项
  • 上传下载:≤4MB 文件单 PUT 上传,大文件自动启用可恢复上传会话;下载通过预认证临时 URL
  • 移动复制重命名:PATCH 更新元数据、POST 复制、DELETE 删除
  • 共享功能:生成匿名/组织内分享链接、邀请特定用户并设置读写权限
  • 高级查询:支持 OData $select、$filter、$orderby、$expand 参数

三种调用方式:

  1. CLI:maton one-drive item list、maton api /one-drive/v1.0/...
  2. 直接 HTTP:向 https://api.maton.ai/one-drive/v1.0/ 发送请求,Header 携带 Authorization: Bearer $MATON_API_KEY
  3. 编程语言:文档提供 Python、JavaScript 完整示例

多账户管理:通过 maton connection create one-drive 创建多个 OAuth 连接,使用 --connection {id} 或 Maton-Connection Header 指定目标账户。

显著优点

  1. 零代码集成:纯文档 Skill 无本地依赖,无需安装 Microsoft SDK 或处理复杂的 OAuth 流程,Maton 自动管理 Token 刷新
  2. 企业级安全:所有传输 TLS 1.2+ 加密,API Key 通过环境变量注入,无硬编码凭证风险
  3. 完整功能覆盖:支持 Microsoft Graph OneDrive API 的全部核心操作,包括大文件分片上传、分享权限精细控制
  4. 多语言示例:提供 CLI、Python、JavaScript 三种调用范式,降低接入门槛
  5. 来源可信:发布于 clawhub.ai T2 级别平台,MIT-0 开源协议,作者 byungkyu 经过平台认证

潜在缺点与局限性

  1. 代理依赖:必须依赖 Maton 服务可用性,无法直连 Microsoft Graph,存在额外的网络跳转和潜在单点故障
  2. API Key 成本:需注册 Maton 账户并获取 API Key,可能涉及平台使用费用(文档未明确免费额度)
  3. 个人 OneDrive 限制:文档特别说明个人版 OneDrive 中,除 me/drive 外的其他 Drive ID(如 b!... 前缀)可能返回 HTTP 400
  4. 大文件上传复杂度:>4MB 文件需手动处理分片上传流程,虽然 CLI 自动处理,但直接 HTTP 调用需自行实现
  5. 下载 URL 临时性:@microsoft.graph.downloadUrl 为短期预认证链接,不适合长期存储或分发
  6. 无可执行代码:作为 T-MD 纯文档 Skill,实际执行依赖外部 CLI 或用户自行实现的 HTTP 客户端,无内置重试、缓存等机制

适合人群

  • 开发者/运维工程师:需要自动化 OneDrive 文件同步、备份、迁移脚本
  • AI Agent 构建者:为 Claude、GPT 等 AI 助手扩展云存储能力,实现"保存到网盘"、"读取用户文档"等功能
  • 低代码/无代码用户:通过 Maton CLI 快速完成文件管理,无需编写复杂代码
  • 企业用户:需要安全、托管的 OAuth 方案,避免自行维护 Microsoft Graph 集成基础设施

常规风险

风险类型 等级 说明
OAuth Token 泄露 中 连接管理 URL 包含 session_token,需在安全环境打开,避免截图或日志泄露
误操作数据丢失 中 文档已声明"所有写操作需用户明确批准",但仍需注意 delete、replace 等操作的不可逆性
API Key 泄露 低 若 MATON_API_KEY 环境变量被其他进程读取或意外提交到代码仓库,可能导致账户被滥用
Rate Limit 低 Microsoft Graph 存在限流(429 错误),高频批量操作需实现退避重试
依赖服务变更 低 Microsoft Graph API 版本升级或 Maton 平台调整可能影响兼容性

技能正文


name: one-drive description: | OneDrive API integration with managed OAuth via Microsoft Graph. Manage files, folders, and sharing. Use this skill when users want to upload, download, organize, or share files in OneDrive. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key. metadata: author: maton version: "1.0" clawdbot: emoji: 🧠 requires: env: - MATON_API_KEY

OneDrive

Access the OneDrive API with managed OAuth authentication via Microsoft Graph. Manage files, folders, drives, and sharing with full CRUD operations.

Quick Start

CLI:

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

Python:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/one-drive/v1.0/me/drive/root/children')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Base URL

https://api.maton.ai/one-drive/v1.0/{resource}

Maton proxies requests to graph.microsoft.com and automatically injects your OAuth token.

Installation

NPM:

npm install -g @maton/cli

Homebrew:

brew install maton-ai/cli/maton

Authentication

CLI:

maton login                          # Opens browser for API key
maton login --interactive            # Skip browser, paste API key directly
maton whoami                         # Show current auth state

Manual:

  1. Sign in or create an account at maton.ai
  2. Go to maton.ai/settings
  3. Copy your API key
  4. Set your API key as MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"

Connection Management

Manage your OneDrive OAuth connections at https://api.maton.ai.

List Connections

CLI:

maton connection list one-drive --status ACTIVE
maton api -X GET /connections -f app=one-drive -f status=ACTIVE

Python:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections?app=one-drive&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Create Connection

CLI:

maton connection create one-drive
maton api /connections -f app=one-drive

Python:

python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'one-drive'}).encode()
req = urllib.request.Request('https://api.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Get Connection

CLI:

maton connection view {connection_id}
maton api /connections/{connection_id}

Python:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Response:

{
  "connection": {
    "connection_id": "{connection_id}",
    "status": "ACTIVE",
    "creation_time": "2026-02-07T08:23:30.317909Z",
    "last_updated_time": "2026-02-07T08:24:04.925298Z",
    "url": "https://connect.maton.ai/?session_token=...",
    "app": "one-drive",
    "metadata": {}
  }
}

Open the returned url in a browser to complete OAuth authorization.

Delete Connection

CLI:

maton connection delete {connection_id}
maton api -X DELETE /connections/{connection_id}

Python:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Specifying Connection

If you have multiple OneDrive connections, specify which one to use:

CLI:

maton one-drive item list --connection {connection_id}
maton api /one-drive/v1.0/me/drive/root/children --connection {connection_id}

Python:

python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/one-drive/v1.0/me/drive')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '{connection_id}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

If you have multiple connections, always specify the connection to ensure requests go to the intended account.

Security & Permissions

  • Access is scoped to files, folders, and sharing within the connected OneDrive account.
  • All write operations require explicit user approval. Before executing any create, update, or delete call, confirm the target resource and intended effect with the user.

API Reference

Drives

Get Current User's Drive
GET /one-drive/v1.0/me/drive

Example:

maton one-drive whoami
List User's Drives
GET /one-drive/v1.0/me/drives

Example:

maton one-drive drive list
Get Drive by ID
GET /one-drive/v1.0/drives/{drive-id}

Example:

maton one-drive drive view {drive-id}

Files and Folders

Get Drive Root
GET /one-drive/v1.0/me/drive/root

Example:

maton one-drive item view root
List Root Children
GET /one-drive/v1.0/me/drive/root/children

Example:

maton one-drive item list
Get Item by ID
GET /one-drive/v1.0/me/drive/items/{item-id}

Example:

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

Example:

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

Example:

maton one-drive item list Documents
Get Item Children
GET /one-drive/v1.0/me/drive/items/{item-id}/children

Example:

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

Example:

maton one-drive item view --special documents

Recent and Shared

Get Recent Files
GET /one-drive/v1.0/me/drive/recent

Example:

maton one-drive drive recent
Get Files Shared With Me
GET /one-drive/v1.0/me/drive/sharedWithMe

Example:

maton one-drive drive shared

Search

GET /one-drive/v1.0/me/drive/root/search(q='budget')

Example:

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"
}

Example:

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": {}
}

Example:

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}

Example:

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"
  }
}

Example:

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}

Example:

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"
}

Example:

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}"
  }
}

Example:

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"
}

Example:

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}

Example:

maton one-drive item delete {item-id}

Returns 204 No Content on success.

Sharing

Create Sharing Link
POST /one-drive/v1.0/me/drive/items/01ABCDEF/createLink
Content-Type: application/json

{
  "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

Example:

maton one-drive item share 01ABCDEF --type view --scope anonymous
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!"
}

Example:

maton one-drive item invite {item-id} --emails user@example.com --roles read --message 'Check out this file!'

Query Parameters

Customize responses with OData query parameters:

  • $select - Choose specific properties: ?$select=id,name,size
  • $expand - Include related resources: ?$expand=children
  • $filter - Filter results: ?$filter=file ne null (files only)
  • $orderby - Sort results: ?$orderby=name asc
  • $top - Limit results: ?$top=10

Example:

GET /one-drive/v1.0/me/drive/root/children?$select=id,name,size&$top=20&$orderby=name%20asc
maton one-drive item list --select id,name,size --top 20 --orderby 'name asc'

Pagination

OneDrive uses cursor-based pagination. The CLI automatically paginates with '--paginate'.

Example:

maton one-drive item list --paginate

Code Examples

CLI

# Search for files
maton one-drive drive search 'budget'

# Share a file
maton one-drive item share 01ABCDEF --type view --scope anonymous

# Extract specific fields with --jq (requires --json)
maton one-drive item view root --json --jq '.name'

JavaScript

// List files in root
const response = await fetch(
  'https://api.maton.ai/one-drive/v1.0/me/drive/root/children',
  {
    headers: {
      'Authorization': `Bearer ${process.env.MATON_API_KEY}`
    }
  }
);
const data = await response.json();

// Upload a file
const uploadResponse = await fetch(
  'https://api.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
  {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${process.env.MATON_API_KEY}`,
      'Content-Type': 'text/plain'
    },
    body: 'Hello, OneDrive!'
  }
);

Python

import os
import requests

# List files in root
response = requests.get(
    'https://api.maton.ai/one-drive/v1.0/me/drive/root/children',
    headers={'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
)
files = response.json()

# Upload a file
upload_response = requests.put(
    'https://api.maton.ai/one-drive/v1.0/me/drive/root:/myfile.txt:/content',
    headers={
        'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}',
        'Content-Type': 'text/plain'
    },
    data='Hello, OneDrive!'
)

Notes

  • OneDrive uses Microsoft Graph API (graph.microsoft.com)
  • Item IDs are unique within a drive
  • Use colon (:) syntax for path-based addressing: /root:/path/to/file
  • Files ≤4MB upload via a single PUT; larger files automatically use a resumable upload session
  • Download URLs from @microsoft.graph.downloadUrl are pre-authenticated and temporary
  • Conflict behavior options: fail, replace, rename
  • On personal OneDrive accounts, only the user's own drive ID (returned by whoami) is directly addressable. The additional b!...-prefixed IDs that appear in drive list return HTTP 400 from Microsoft Graph when fetched this way. Use me/drive instead.
  • IMPORTANT: When using curl commands, use curl -g when URLs contain brackets to disable glob parsing
  • IMPORTANT: When piping curl output to jq or other commands, environment variables like $MATON_API_KEY may not expand correctly in some shell environments

Error Handling

Status Meaning
400 Missing OneDrive connection or invalid request
401 Invalid or missing Maton API key
403 Insufficient permissions
404 Item not found
409 Conflict (e.g., item already exists)
429 Rate limited (check Retry-After header)
4xx/5xx Passthrough error from Microsoft Graph API

Error Response Format

{
  "error": {
    "code": "itemNotFound",
    "message": "The resource could not be found."
  }
}

Troubleshooting: API Key Issues

CLI:

  1. Check your auth state:
maton whoami
  1. Verify the API key is valid by listing connections:
maton connection list

Manual:

  1. Check that the MATON_API_KEY environment variable is set:
echo $MATON_API_KEY
  1. Verify the API key is valid by listing connections:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://api.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF

Troubleshooting: Invalid App Name

  1. Ensure your URL path starts with one-drive. For example:
  • Correct: https://api.maton.ai/one-drive/v1.0/me/drive/root/children
  • Incorrect: https://api.maton.ai/v1.0/me/drive/root/children

Resources

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

microsoft-graphfile-storagecloud-syncoauth-proxyapi-gatewayenterprise-integration

同类 Skill