You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何使用OneNote Graph API将OneNote页面设置为只读

Set OneNote Page to Read-Only via Microsoft Graph API

Hey there! Let's break down how to make a OneNote page read-only using the Graph API. First, a quick heads-up: there's no direct isReadOnly property you can patch on the page itself. Instead, we have two main approaches—one official and secure, one a quick editor-only workaround.

1. Official Method: Restrict User/Group Permissions

The most reliable way to enforce read-only access is to update the item-level permissions for the page. Here's the step-by-step:

Step 1: Fetch Existing Permissions

First, get the current permissions for your target page to identify the permission entry you need to modify:

GET https://graph.microsoft.com/v1.0/me/onenote/pages/{page-id}/permissions
Authorization: Bearer {your-access-token}

Step 2: Patch the Permission to Read-Only

Use the permission-id from the previous response to update the role to read for the user/group you want to restrict:

PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/{page-id}/permissions/{permission-id}
Authorization: Bearer {your-access-token}
Content-Type: application/json

{
  "roles": ["read"]
}
  • Replace {page-id} with your target page's unique ID, and {permission-id} with the ID of the specific permission entry you retrieved.
  • This method ensures the user/group can't edit the page at all, which is the true read-only enforcement.

2. Workaround: Lock Page Content (Editor-Only)

If you just want to prevent accidental edits in the OneNote editor (this doesn't block API-based edits), you can patch the page content to disable interaction:

PATCH https://graph.microsoft.com/v1.0/me/onenote/pages/{page-id}/content
Authorization: Bearer {your-access-token}
Content-Type: application/json

[
  {
    "target": "body",
    "action": "replace",
    "content": "<div style='pointer-events: none; user-select: none;'>[Paste your existing page content here]</div>"
  }
]
  • Note: This is a visual hack only. Anyone with edit permissions can still modify the content via the API or remove the styling in the editor.

Key Limitation to Keep in Mind

As of Graph API v1.0 and beta versions, there's no native endpoint to mark a OneNote page as globally read-only for all users. The permission-based approach is the only official, secure way to enforce read-only access.

内容的提问来源于stack exchange,提问作者rammohan reddy

火山引擎 最新活动