SharePoint Document Issues

How to Delete SharePoint Files Using REST API and jQuery

Adam DavisAdam Davis Oct 22, 2026 870 views

Question details

The user needs to delete a SharePoint document programmatically using a REST API request and jQuery, but encounters permission and header configuration issues.

How to Delete SharePoint Files Using REST API and jQuery
Product
Microsoft SharePoint
Device & OS
not provided
Scenario
Attempting to delete files dynamically through custom frontend scripts using SharePoint REST API and jQuery AJAX calls.
Observed behavior
The REST API request returns a 'Forbidden' error when trying to delete a document, even though uploading the document works properly and the user appears to hold delete permissions.
Before you start

Verify that you have the exact server-relative URL of the target file and ensure you have administrative access to register applications within Microsoft Entra ID.

Solution 1Recommended

Configure jQuery AJAX POST Request with DELETE Headers

By registering your app in Entra ID and using a POST request with specific override headers, you can bypass the Forbidden error and successfully delete the file.

In many SharePoint environments, direct DELETE requests are blocked for security or routing reasons. To work around this, developers should issue a standard POST request and instruct the server to process it as a deletion by injecting the X-HTTP-Method header.

1
Obtain an Access Token

Register your application in Microsoft Entra ID (formerly Azure AD) and request a valid Bearer access token configured for SharePoint API permissions.

2
Construct the Endpoint URL

Define your API endpoint using the server-relative path of the file. Use the format: _api/web/GetFileByServerRelativeUrl('/sites/siteName/libraryName/fileName.docx').

3
Configure the jQuery AJAX Call

Set the AJAX type to 'POST' instead of 'DELETE', and include your Bearer token in the Authorization header.

4
Add Override Headers

Inside the AJAX headers object, add 'X-HTTP-Method': 'DELETE' to trigger the deletion, and 'If-Match': '*' to bypass eTag validation checks.

Permanent Deletion Warning: Calling the delete method via REST API in this manner permanently deletes the file, skipping the SharePoint Recycle Bin entirely. Please ensure you have backups if needed.
Free Microsoft Office alternative

Simplify Your Document Management with WPS Office

While resolving SharePoint API endpoints requires extensive debugging and custom scripts, managing your everyday office documents should be straightforward. WPS Office provides a streamlined, highly compatible environment to handle all your word processing, spreadsheets, and presentations without complex setups.

Fully compatible with Microsoft Office file formats (.docx, .xlsx, .pptx).Lightweight application that opens large files significantly faster.Familiar user interface allowing for a seamless transition with zero learning curve.Built-in PDF tools to convert, edit, and sign documents easily.
microsoft office alternative - wps office

Frequently Asked Questions

Why am I getting a 403 Forbidden error despite having delete permissions?

A 403 Forbidden error often occurs if your application is not properly authenticated via Microsoft Entra ID, if the generated access token lacks the correct scope for deletion, or if a required Request Digest token is missing from the headers.

Can I move the file to the Recycle Bin instead of permanently deleting it via REST API?

Yes. Instead of using the DELETE method, send a POST request to the recycle endpoint: _api/web/GetFileByServerRelativeUrl('path/to/file')/recycle(). This safely moves the file to the site's Recycle Bin.

What is the purpose of the 'If-Match: *' header?

The 'If-Match: *' header instructs the SharePoint server to execute the deletion regardless of the file's current version. It overrides the eTag concurrency checks, which would otherwise block the request if the file had been recently modified.