Back

OneNote API Essential Guide

Aug 2, 20246 minute read

What type of API does OneNote provide?

OneNote primarily uses a REST API. The OneNote API is part of Microsoft Graph, which provides a REST API. The root URL for accessing OneNote data through Microsoft Graph uses the following REST format:

https://graph.microsoft.com/{version}/{location}/onenote/

Microsoft Graph allows apps to get authorized access to a user's OneNote notebooks, sections, and pages using REST API calls. Examples of REST API calls for OneNote include:

  • GET my notebooks: https://graph.microsoft.com/v1.0/me/onenote/notebooks
  • GET my sections: https://graph.microsoft.com/v1.0/me/onenote/sections
  • GET my pages: https://graph.microsoft.com/v1.0/me/onenote/pages

The OneNote API in Microsoft Graph is available in both v1.0 (stable) and beta versions.

Does the OneNote API have webhooks?

The OneNote API does not have native webhook support or an event subscription system. Microsoft Graph, which includes OneNote functionality, does offer webhooks and subscriptions for various services, but OneNote is not currently among them.

Key points:

• The OneNote API focuses on CRUD operations for notebooks, sections, and pages.

• Real-time notifications are not available through webhooks, but the API provides methods to sync changes and retrieve recent changes.

• Microsoft Graph has webhook capabilities for other services like Outlook and OneDrive, but not for OneNote.

• Developers seeking real-time updates in OneNote may need to implement polling mechanisms or explore alternative solutions.

Code example for retrieving recent changes:

import requests access_token = "YOUR_ACCESS_TOKEN" url = "https://graph.microsoft.com/v1.0/me/onenote/pages?$filter=lastModifiedDateTime ge 2024-02-01T00:00:00Z" headers = { "Authorization": f"Bearer {access_token}", "Accept": "application/json" } response = requests.get(url, headers=headers) if response.status_code == 200: recent_changes = response.json() for page in recent_changes['value']: print(f"Page title: {page['title']}, Last modified: {page['lastModifiedDateTime']}") else: print(f"Error: {response.status_code}, {response.text}")

Best practices:

  1. Focus on efficient use of available endpoints for syncing and retrieving changes.

  2. Consider implementing a polling mechanism if near real-time updates are necessary.

  3. Stay updated with Microsoft Graph documentation for potential future webhook support for OneNote.

  4. Explore Microsoft Graph change notifications for other services that might be relevant to your OneNote-related application.

In conclusion, while the OneNote API doesn't offer webhooks or event subscriptions, developers can achieve similar functionality through careful use of available API endpoints and alternative synchronization methods.

Rate Limits and other limitations

The OneNote API, which is part of Microsoft Graph, has specific rate limits to ensure fair usage and prevent abuse. Here are the key points regarding the API rate limits for OneNote:

  1. General Rate Limit:

    • The OneNote API follows the general Microsoft Graph rate limit of 10,000 requests per 10 minutes per app per tenant.
  2. Per-User Rate Limit:

    • There is also a per-user rate limit of 600 requests per minute.
  3. Throttling:

    • If an application exceeds these limits, it will receive a 429 Too Many Requests response.
    • The response will include a Retry-After header, indicating how long the application should wait before making another request.
  4. Best Practices:

    • Implement retry logic in your application to handle 429 responses.
    • Use batch requests when possible to reduce the number of API calls.
    • Spread out requests over time to avoid hitting rate limits.
  5. Additional Considerations:

    • Rate limits may vary depending on the specific OneNote API endpoint being used.
    • Microsoft may adjust these limits without notice to ensure the best possible experience for all users.
  6. Monitoring:

    • Use the response headers to track your remaining quota and adjust your request rate accordingly.

It's important to note that these rate limits are subject to change, and developers should always refer to the official Microsoft Graph documentation for the most up-to-date information on API rate limits and best practices for working with the OneNote API.

Latest API Version

Based on the information provided, here are the key points regarding the most recent version of the OneNote API:

Current API Version

The most recent version of the OneNote API is part of Microsoft Graph API v1.0. Microsoft Graph provides two versions:

  1. v1.0 - This is the stable production version.
  2. beta - This is for features in development and not recommended for production use.

API Access

The OneNote API can be accessed through Microsoft Graph using the following root URL format:

https://graph.microsoft.com/{version}/{location}/onenote/

Where:

  • {version} is either "v1.0" or "beta"
  • {location} depends on the type of notebooks you're accessing (user, group, or SharePoint site)

Key Points

  • The OneNote API is integrated into Microsoft Graph, allowing access to notebooks, sections, and pages.
  • It supports both personal and organizational accounts.
  • Proper permissions (delegated or application) are required to access OneNote data.
  • The API allows for various operations like creating, reading, updating, and deleting OneNote content.

Best Practices

  • Use the v1.0 endpoint for stable production code.
  • Ensure you have the appropriate permissions set up for your application.
  • Be aware of the different URL structures for accessing user notebooks, group notebooks, and SharePoint site notebooks.

Summary

The most recent production version of the OneNote API is part of Microsoft Graph v1.0. It provides a comprehensive set of features for interacting with OneNote content and is accessed through the Microsoft Graph API endpoints.

How to get a OneNote developer account and API Keys?

To get a developer account for OneNote and create an API integration, follow these steps:

  1. Sign up for a Microsoft account: Create a Microsoft account at https://account.microsoft.com/account.

  2. Register as a developer: Go to the Microsoft 365 Developer Program website https://developer.microsoft.com/en-us/microsoft-365/dev-program and sign up for a free developer account.

  3. Set up your developer environment: Once registered, you'll have access to a Microsoft 365 developer subscription, which includes tools and resources for developing with Microsoft products, including OneNote.

  4. Access the Microsoft Graph API: OneNote API is part of the Microsoft Graph API. You'll use this to interact with OneNote data.

  5. Register your application: • Go to the Azure Active Directory admin center https://aad.portal.azure.com/ • Navigate to "App registrations" and click "New registration" • Fill in the required information for your app • Once registered, you'll receive a client ID (also known as application ID)

  6. Configure permissions: In your app's registration, add the necessary permissions for OneNote. These might include "Notes.Read", "Notes.ReadWrite", etc., depending on your app's requirements.

  7. Obtain authentication tokens: To make API calls, you'll need to authenticate your requests. This typically involves obtaining an access token using OAuth 2.0.

  8. Start developing: With your app registered and permissions set, you can now start making API calls to OneNote using the Microsoft Graph API.

What can you do with the OneNote API?

Here's a list of data models you can interact with using the OneNote API, along with bullet points describing what is possible for each:

Notebooks

  • Create new notebooks
  • Retrieve a list of notebooks
  • Get details of a specific notebook
  • Update notebook properties
  • Delete notebooks

Sections

  • Create new sections within a notebook
  • Retrieve a list of sections in a notebook
  • Get details of a specific section
  • Update section properties
  • Delete sections
  • Move sections between notebooks

Pages

  • Create new pages within a section
  • Retrieve a list of pages in a section
  • Get the content of a specific page
  • Update page content and properties
  • Delete pages
  • Move pages between sections
  • Copy pages

Page Content

  • Add text, images, and other content to pages
  • Retrieve specific content elements from a page
  • Update existing content on a page
  • Delete content from a page

Tags

  • Add tags to page content
  • Retrieve tags associated with content
  • Remove tags from content

Attachments

  • Add file attachments to pages
  • Retrieve attachments from pages
  • Delete attachments from pages

Images

  • Insert images into pages
  • Retrieve image metadata and content
  • Update image properties
  • Delete images from pages
  • Create links between pages or to external resources
  • Retrieve link information
  • Update link properties
  • Remove links from pages

Tables

  • Create tables within pages
  • Retrieve table data
  • Update table content and structure
  • Delete tables from pages

Outlines

  • Create outlines (hierarchical lists) within pages
  • Retrieve outline structure and content
  • Update outline items
  • Delete outlines from pages
  • Perform full-text search across notebooks, sections, and pages
  • Filter search results based on various criteria

Permissions

  • Set and manage permissions for notebooks and sections
  • Retrieve permission information for shared content

Versioning

  • Retrieve version history of pages
  • Restore previous versions of pages

These data models and operations allow developers to interact with various aspects of OneNote content through the API, enabling the creation, retrieval, updating, and deletion of different elements within the OneNote structure.