If you are getting 403 Forbidden exception while creating, editing or deleting a SharePoint Online list item using REST API, follow steps given below to fix the error.
{
"error":{
"code":"-2130575251, Microsoft.SharePoint.SPException",
"message":{
"lang":"en-US",
"value":"The security validation for this page is invalid and might be corrupted. Please use your web browser's Back button to try your operation again."
}
}
}
When creating, updating or deleting SharePoint entities, you need to authorize the requests, they require the server request form digest value as the value of the X-RequestDigest header.
The value can be retrieved by making a POST request with an empty body to http://site url/_api/contextinfo and extracting the value of the d:FormDigestValue node in the XML that the contextinfo endpoint returns.
✔️ Solution - Add "X-RequestDigest": $("#__REQUESTDIGEST").val() to the header of your Ajax as below to fix the security validation error.
Note the double underscore __ which needs to be passed as-is.
headers:{
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
Remote add-ins using OAuth can get the form digest value from the http://site url/_api/contextinfo endpoint.
SharePoint-hosted add-ins which run within SharePoint context can get the value from the #__REQUESTDIGEST page control if it's available on the SharePoint page.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- SharePoint error - An exception occurred when trying to issue security token: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms..
- PowerShell iterate and get all SharePoint sites and sub sites
- SharePoint Online: Editing session has ended Message
- How to Share Microsoft SharePoint Site with Users or Groups
- How to delete SharePoint Online List Item using REST API
- SharePoint List excel import - This table exceeds the maximum number of supported rows
- How to disable SharePoint subsite creation option for owners
- SharePoint 2010 August 2015 Update KB3055049 - Duplicate Document ID issue bug fixed
- SharePoint Server 2016 Preview installation error - This Product Key isn't a valid Microsoft Office 2016 Product Key. Check that you've entered it correctly.
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- Access URL for SharePoint Tenant Admin Center (Online Office 365)
- Error when deleting SharePoint Online folder or file
- How to extend retiring SharePoint 2010 Workflows and continue with Office 365
- How to generate client id and secret to register SharePoint App with OAuth
- How to delete SharePoint List Item programmatically using C#.Net
- How to retrieve all SharePoint Online List Items using Rest API
- [Solved] SharePoint Search Internal server error exception
- Create SharePoint Site Collection using PowerShell New-SPSite
- Fix SharePoint PowerShell error - The term Get-SPweb is not recognized as the name of a cmdlet function script file or operable program
- How to enable anonymous public access for SharePoint Online site collection, file, folder without login ?
- SharePoint Server 2016 installation System Hardware requirements
- How to create SharePoint Online List Item using REST API
- Changed AD user display name showing old name in SharePoint
- Recommended size and resolution for SharePoint Online Site logo
- Microsoft 365: How to Turn Off Delve in SharePoint Online for All Users
- How to embed web page in SharePoint - SharePoint
- [fix] Chrome: no listeners for an event URLS_SAFE_CHECK__STATUS_UPDATED - Chrome
- Create assets folder in Android Studio - Android-Studio
- How to Install Git on Windows - Git
- How to create Custom RatingBar Android Programming Tutorial - Android
- How to enable line numbers in Eclipse IDE - Eclipse
- How to check the version of Python Modules - Python
- Enable Spellcheck in eclipse workspace - Eclipse