Back

OneDrive API Essential Guide

Aug 1, 20246 minute read

What type of API does OneDrive provide?

OneDrive utilizes a REST API as part of the Microsoft Graph API.

Type of API

  • OneDrive uses a REST API
  • The OneDrive REST API is part of the larger Microsoft Graph API

API Structure

  • Has top-level resources like drives, items, and shares
  • Uses properties, facets, and references to represent data
  • Supports query parameters to customize responses

Relationship to Microsoft Graph

  • OneDrive API is part of the unified Microsoft Graph API
  • Allows access to OneDrive data alongside other Microsoft 365 services

In summary, OneDrive uses a REST API that is part of the Microsoft Graph ecosystem, providing a standardized way to interact with OneDrive resources using HTTP methods and JSON responses.

Does the OneDrive API have webhooks?

Yes, the OneDrive API supports webhooks. Here are the key points:

Webhook Support

  • OneDrive provides service-to-service notifications through webhooks.
  • Webhooks allow your app to be notified of changes to a user's drive without polling the service.

Event Types

The main event type you can subscribe to is:

  • "updated" - Triggered when items in the subscribed scope are changed.

Subscription Scope

  • You can subscribe to notifications for changes to a user's entire drive or specific folders/items.
  • The subscription is scoped to items the app has access to within the user's drive.

Notification Details

  • The webhook notification doesn't include details about the specific changes.
  • It only notifies that a change occurred within the subscribed scope.
  • Your app is expected to use the delta API to detect the actual changes.

Best Practices

  • Respond quickly to notifications (within seconds).
  • Handle concurrent notifications for the same user.
  • Use a service-to-service model rather than notifying client devices directly.
  • Implement proper error handling and respect exponential backoff for failed notifications.

Limitations

  • Permission changes may not consistently trigger webhook notifications.

To subscribe to webhooks, you need to register a notification URL with the OneDrive API. The API will validate the URL before creating the subscription.

In summary, OneDrive webhooks provide a way to be notified of changes, focusing on general "update" events. For more granular change tracking, combine webhooks with other API calls like the delta API.

Rate Limits and other limitations

Here are the key points about API rate limits for the OneDrive API:

General Throttling Approach

  • OneDrive implements throttling to prevent individual users or apps from adversely affecting the experience of other users.

  • When an activity exceeds OneDrive's limits, API requests will be rejected for a period of time.

  • OneDrive may return a Retry-After header indicating how long to wait before sending more requests.

Specific Limits

  • For OneDrive, OneDrive for Business, and SharePoint Online, the specific service limits are not publicly disclosed.

  • Microsoft intentionally does not reveal the exact throttling limits.

  • There is no way for developers to increase the throttling limits.

  • OneDrive does not offer a paid service to increase limits.

Best Practices

  • Use JSON batching to combine multiple requests into one HTTP call, which can help mitigate throttling.

  • Implement retry logic with exponential backoff when encountering throttling errors.

  • For large data extraction, consider using Microsoft Graph Data Connect instead of REST APIs to avoid throttling.

  • Gradually increase traffic to allow OneDrive to "learn" your request patterns.

Monitoring and Debugging

  • Use the Microsoft Graph Developer Proxy tool to simulate throttling behaviors.

  • Pay attention to RateLimit headers in responses, though these are in beta and not always accurate.

  • The only way to determine exact limits is through trial and error, but this is not recommended as it could be seen as a denial of service attack.

In summary, while specific rate limits are not published, OneDrive implements throttling to ensure fair usage. Developers should implement best practices like batching and retry logic, and gradually ramp up usage for enterprise applications. Microsoft generally allows reasonable usage without throttling as long as traffic doesn't suddenly spike.

Latest API Version

Based on the search results provided, I don't have specific information about the most recent version of the OneDrive API. However, I can provide some relevant information about OneDrive API and its recent updates:

Current OneDrive Sync App Versions

The most recent versions of the OneDrive sync app mentioned in the search results are:

  • For Windows: Version 24.126.0623.0001 (July 3, 2024)
  • For Mac: Version 24.126.0623.0001 (July 3, 2024)

Recent Updates and Features

While these are not specifically about the API version, they indicate recent developments in OneDrive:

  1. Exclude file extensions from syncing: Personal users can now configure file extensions to be excluded from syncing to the cloud from OneDrive Sync Settings.

  2. Shortcut files excluded by default: New shortcut files (with .lnk extension) will now be excluded from syncing to the cloud.

  3. Updates to Office File Collaboration Setting: The OneDrive sync app advanced settings for Office file collaboration have been updated. This setting is enabled by default, and users will no longer be able to disable it from the settings dialog.

  4. Automatic updates using .pkg installer on Mac: This addresses some bugs with Files On-Demand on macOS.

  5. Updated experience for Office document conflict resolution: The option to fork documents during conflict resolution has been removed.

API Information

The OneDrive file storage API is part of Microsoft Graph. The search results mention both v1.0 and beta versions of the API, but do not specify the most recent version number.

Key Points to Consider

  • The OneDrive API is integrated into Microsoft Graph, providing a unified API for accessing files from OneDrive personal, OneDrive for Business, and SharePoint.

  • For developers working with the API, it's recommended to check the official Microsoft documentation for the most up-to-date information on API versions and features.

  • Microsoft regularly updates the OneDrive sync app and its API, so it's important to stay informed about the latest changes and features.

In conclusion, while I don't have the specific version number of the most recent OneDrive API, the information provided shows that OneDrive and its API are actively maintained and updated. For the most accurate and current information about the API version, it would be best to consult the official Microsoft Graph documentation or developer resources.

How to get a OneDrive developer account and API Keys?

Here's how you can get a developer account for OneDrive to create an API integration:

Key Steps:

  1. Register your application with Microsoft
  2. Set up authentication and authorization
  3. Start using the OneDrive API via Microsoft Graph

Registering Your Application

  1. Go to the Azure App registrations page [https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade].

  2. Sign in with your Microsoft account (personal, work, or school account).

  3. Click "New registration" and provide the required information:

    • Name for your application
    • Supported account types (personal, work/school, or both)
    • Redirect URI (for OAuth flow)
  4. After registering, you'll receive an Application ID. Save this as you'll need it later.

  5. If your app is a confidential client (e.g., a web service), create a new client secret for authentication.

Setting Up Authentication

  1. Configure the authentication settings for your app under the "Authentication" section.

  2. For OAuth 2.0, you'll need to implement the authorization flow to obtain access tokens.

  3. Your app will use these tokens in the Authorization header when making API requests.

Using the OneDrive API

  1. The OneDrive API is part of Microsoft Graph. Use the Microsoft Graph endpoint: [https://graph.microsoft.com/v1.0].

  2. Construct API requests using the appropriate resource paths, e.g.:

    • /me/drive for the user's OneDrive
    • /drives/{drive-id} for a specific drive
    • /me/drive/root:/path/to/file for accessing files
  3. Include the access token in the Authorization header of your requests.

What can you do with the OneDrive API?

Here are the key data models you can interact with using the OneDrive API, along with what is possible for each:

Drive

  • Represents a drive in OneDrive (personal drive) or SharePoint (document library)
  • Get metadata about the drive
  • List items and folders in the drive
  • Create, update, delete folders and files
  • Search for items in the drive
  • Get drive usage information

DriveItem

  • Represents a file, folder or other item in a drive
  • Get metadata about the item (name, size, created date, etc.)
  • Download file contents
  • Upload new files or update existing file contents
  • Move, copy, rename items
  • Delete items
  • Get thumbnails for files
  • Work with file versions

Permissions

  • View and manage sharing permissions on drive items
  • Create sharing links
  • Add, remove, update permissions for users and groups

Subscriptions

  • Create webhooks to receive notifications when items change

Special Folders

  • Access well-known folders like Documents, Photos, Camera Roll
  • Create app folders to store app-specific data

Thumbnails

  • Get thumbnail images for files in various sizes
  • Search for files and folders across OneDrive

Sharing

  • Share files and folders with other users
  • Manage existing shares
  • Create sharing links

Sync

  • Get sync status of items
  • Manage sync relationships

File Handlers

  • Register custom file handlers for file types
  • Add custom actions to the OneDrive UI

File Picker

  • Integrate OneDrive file picker into your app

The OneDrive API provides comprehensive capabilities to work with files and folders stored in OneDrive and SharePoint document libraries, enabling apps to fully integrate with the OneDrive ecosystem.