logo
search
Others

How to Delete a OneDrive File by URL Using the OneDrive API

Amos GikundaAmos Gikunda Sep 30, 2026 868 views

Question details

Developers are looking for a way to delete a file in OneDrive using its URL rather than the standard Microsoft Graph or OneDrive file ID.

How to Delete a OneDrive File by URL Using the OneDrive API
Product
OneDrive API / Microsoft Graph
Device & OS
not provided
Scenario
A developer needs to programmatically delete a OneDrive file but only has access to the file's sharing URL or web URL.
Observed behavior
The API documentation primarily focuses on deletion via file ID, leaving developers unsure of the correct request format to delete directly via URL.
Before you start

Ensure you have an active Microsoft Graph access token and that your application has been granted the necessary permissions (such as Files.ReadWrite.All) to modify or delete files.

Solution 1Recommended

Resolve the URL to a DriveItem using Microsoft Graph API

While you cannot delete a file directly using just the web URL in a single endpoint, you can use the Graph API to resolve the URL into a DriveItem and then delete it using the retrieved file ID.

The Microsoft Graph API allows you to encode a sharing URL and use the 'shares' endpoint to access the corresponding DriveItem. Once the item's unique ID is retrieved, standard deletion methods apply.

1
Encode the URL

Base64 encode the OneDrive file URL. Replace any '/' with '_' and '+' with '-', then append 'u!' to the beginning to create a valid sharing token.

2
Retrieve the DriveItem ID

Make an authenticated GET request to 'https://graph.microsoft.com/v1.0/shares/{encoded-url}/driveItem'. Parse the JSON response to extract the 'id' field.

3
Delete the file

Send a DELETE request to 'https://graph.microsoft.com/v1.0/me/drive/items/{extracted-id}' (or the specific drive path) to permanently remove the file.

Resolve the URL to a DriveItem using Microsoft Graph API
Authentication Required: Both requests require a valid Bearer token in the Authorization header with sufficient write permissions.
Free Microsoft Office alternative

Try WPS Office for Seamless Document Management

While API development and complex cloud integrations require tools like Microsoft Graph, your daily document creation and editing needs can be handled perfectly by WPS Office. It is a lightweight, cost-effective alternative to Microsoft Office that easily manages your local and cloud documents.

  1. 1. Download the software: Visit the official WPS Office website to download the installer for your operating system.
  2. 2. Install and launch: Run the lightweight installer and open the application to access Writer, Spreadsheets, and Presentation modules.
  3. 3. Edit your documents: Open your existing Microsoft Office files and edit them seamlessly without worrying about formatting issues.
Completely free and lightweight office suiteHighly compatible with Microsoft Office formats (DOCX, XLSX, PPTX)Built-in cloud integration for seamless file saving and sharingFamiliar tabbed interface requiring zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Can I perform a DELETE request directly on a OneDrive web URL?

No, standard REST APIs for OneDrive (like Microsoft Graph) do not accept DELETE requests directly on web URLs. You must interact with the API endpoints using the item's unique ID.

What permissions do I need to delete a file via Microsoft Graph API?

Your application must be granted 'Files.ReadWrite' or 'Files.ReadWrite.All' permissions. The token used for the API call must reflect these granted scopes.

How do I test OneDrive API requests before deploying my code?

You can use the Microsoft Graph Explorer, a free web-based tool provided by Microsoft, to safely test GET and DELETE requests on your OneDrive files using your developer account.