SharePoint List item can be updated using REST API by referring to the item by its ID filed which is always unique. Let us look at an example, which can be validated using Postman.
You would eventually use the code snippet with Spfx (modern) or Content Editor (classic). For authentication, bearer token will be used.
If you are connecting to the List from outside of SharePoint like Java, .Net or Python code, you need to use a Bearer token (Client ID and Client Secret) to access the REST url.
Steps to generate Client ID and Secret - Register SharePoint App
This example assumes you have a list named "List1". Please make necessary modifications to the List name, column internal name wherever applicable.
✔️ Update SharePoint List Item using HTML, jQuery, Ajax
We will use POST method to update the SharePoint record. Assumptions,List Name = List1
List Item ID = 10
Column to update = Title
You can update more columns, just pass the internal name and value to be updated. Separate with a comma ",".
var webURL = _spPageContextInfo.webAbsoluteUrl;
$.ajax({
url: webURL + "/_api/web/lists/GetByTitle('List1')/items(10)",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
data: "{__metadata:{'type':'SP.Data.List1ListItem'},Title:'Title updated via REST API'}",
//Add more columns in above line to update
success: function(data) {
//Perform further activity upon success, like displaying a notification
},
error: function(error) {
//Log error and perform further activity upon error/exception
}
});
✔️ Update SharePoint List Item using Postman - PATCH
For testing SharePoint REST API with Postman, you need to use the Client ID, Client Secret, Tenant ID, to generate a Bearer token.Steps to generate SharePoint Bearer token - How to test SharePoint REST API from Postman
Once you have generated the access token, follow below steps
- Initiate a PATCH method request.
- Apply Header configuration parameters as below.
- In the Body section, select 'raw' and add below code.
- Enter request url in below format
- Click Send.
- You should get a 204 No Content response. This means that the update request is successfully completed there is no content to return in response.
- Validate the changes form SharePoint.
Key | Value |
Accept | application/json;odata=verbose |
Content-Type | application/json |
Authorization | Bearer <token> |
If-Match | * |
{
"Title": "Title updated via REST API"
}
https://c2c.sharepoint.com/sites/SPDev/_api/web/lists/GetByTitle('List1')/items(10)
⚠️ Error - The request ETag value does not match the object's ETag value
If you get a 412 Precondition Failed error with message "The request ETag value does not match the object's ETag value", it means the server does not meet one of the preconditions that the requester put on the request.
Solution - Add Header parameter key "If-Match" and set its value as *. The ETag Header is used to ensure you update the latest version of SharePoint list item.
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
"message": {
"lang": "en-US",
"value": "The request ETag value '' does not match the object's ETag value '\"GUID,2\"'."
}
}
}
- error CAML Query containing special characters
- [Solved] SharePoint Illegal operation attempted on a registry key that has been marked for deletion
- Trigger Flow on selected Listitem from SharePoint view - create button with JSON column formatting
- SharePoint Excel error - The workbook cannot be opened because it contains the following features that are not supported by Excel in the browser
- Send Email with attachment using SharePoint PowerShell, SMTP server
- How to show or hide columns in SharePoint Online List Library from
- SharePoint excel error - A problem occurred while connecting to the server. If the problem continues, contact your administrator.
- How to get SharePoint Online user details from person or group column using REST API
- How to get SharePoint List Item URL using PowerShell
- How to get the SharePoint Tenant Login URL
- Special character & not working with SharePoint REST API
- How to disable SharePoint subsite creation option for owners
- Managed Metadata error - The data returned from the tagging UI was not formatted correctly
- Deploy SharePoint wsp solution package using PowerShell
- How to create classic site in SharePoint Online
- See actual SharePoint error exception modify web.config
- 'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher
- How to enable anonymous public access for SharePoint Online site collection, file, folder without login ?
- SharePoint installation error - Setup is unable to proceed due to the following error This product requires Microsoft .Net Framework 4.5
- How to add animated Gif to SharePoint Online Page
- [Solved] SharePoint Search Internal server error exception
- How to create SharePoint Document Library
- SharePoint - Use Today's Date Time in list view filter and calculated column
- How to redirect SharePoint Site Collection to different URL
- SharePoint error cannot connect to the configuration database
- [fix] RabbitMQ: AuthenticationFailureException ACCESS_REFUSED Login refused authentication mechanism PLAIN - 2022
- Convert Javascript object to JSON String example - JavaScript
- 26: How to set Environment Variables using Python - Python
- Program 10: Modulo of Two Numbers - 1000+ Python Programs - Python-Programs
- Java: Create Temporary Directory and File and Delete when application terminates - Java
- Create RabbitMQ Exchange using Java Spring Boot Example - Java
- MySQL : Error :1000 SQLSTATE: HY000 (ER_HASHCHK) Message: hashchk Server Error - MySQL
- How to reset an Apple Watch without an iPhone - Apple