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.
Have Questions? Post them here!
- That did'nt work, Issue type User not in directory - SharePoint external access error
- How to get SharePoint Online user details from person or group column using REST API
- Create SharePoint Site Collection with new Content database in existing web application
- Fix Power BI 404 not found error when connecting SharePoint Online List as Data Source
- How to get the SharePoint Tenant Login URL
- How to wrap column text in SharePoint Online Modern List Grid View using JSON formatting
- SharePoint Server 2016 installation System Hardware requirements
- Cannot load PowerApps form in SharePoint Online due to repeated authentication
- Change SharePoint search results FullTextSqlQuery RowLimit 10000
- How to create SharePoint Document Library
- How to exclude results from SharePoint Search
- SharePoint 2010 DataForm Unable to display this Web Part System.StackOverflowException
- Fix Error 2711 SQL RBS client - The installer has encountered an unexpected error. The specified Feature name ('Docs') not found in Feature table
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- SharePoint error cannot connect to the configuration database
- Drag drop files here option missing for SharePoint document library
- How to activate and create SharePoint Spaces feature for mixed reality experience - 2D/3D images and web parts
- [Fix] Office 365 Sharepoint One Drive Error: Something went wrong. This is a temporary issue
- SharePoint 2016 error - Could not find file ManageUserProfileServiceApplicationTenantSimplified.xml
- SharePoint List excel import - This table exceeds the maximum number of supported rows
- How to customize SharePoint Modern list form using JSON formatting
- New-SPLogFile PowerShell - create new SharePoint log file
- SharePoint Online REST API not returning all list items and limit to only 100 rows
- How to Get or Set SharePoint Document ID _dlc_DocId using PowerShell
- Get-ADUser PowerShell - Get AD user details using email address
- Fix Power Automate FLOW error - InvalidTemplate Unable to process template language expressions in action - Microsoft
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations - Android
- Clone Bitbucket repo in VS Code - HowTos
- Android Installation error: INSTALL_FAILED_OLDER_SDK on Device - Android
- How to enable Do Not Disturb (DND) mode in Microsoft Teams - Teams
- Java code to check Internet Connection on Android Device Programmatically - Android
- How to hide lines in Notepad++ - NotepadPlusPlus
- Format Code in Visual Studio - VS Code [Mac/Windows/Linux] - HowTos