How to Delete SharePoint Files Using REST API and jQuery
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.

- 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.
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.
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.
Register your application in Microsoft Entra ID (formerly Azure AD) and request a valid Bearer access token configured for SharePoint API permissions.
Define your API endpoint using the server-relative path of the file. Use the format: _api/web/GetFileByServerRelativeUrl('/sites/siteName/libraryName/fileName.docx').
Set the AJAX type to 'POST' instead of 'DELETE', and include your Bearer token in the Authorization header.
Inside the AJAX headers object, add 'X-HTTP-Method': 'DELETE' to trigger the deletion, and 'If-Match': '*' to bypass eTag validation checks.
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.

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.




