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\"'."
}
}
}
- Change SharePoint Online List Experience to New Experience from Classic
- Cannot load PowerApps form in SharePoint Online due to repeated authentication
- Create SharePoint list from Excel spreadsheet and import table
- [Solved] SharePoint Search Internal server error exception
- [Fix] SharePoint: This embed code doesnt seem to work. We only support iframe based embeds
- How to extend retiring SharePoint 2010 Workflows and continue with Office 365
- SharePoint Online: Editing session has ended Message
- SharePoint error cannot connect to the configuration database
- That did'nt work, Issue type User not in directory - SharePoint external access error
- How to embed web page in SharePoint
- SharePoint - The URL is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.
- SharePoint error 2130575251 - The security validation for this page is invalid and might be corrupted
- Microsoft 365: How to Turn Off Delve in SharePoint Online for All Users
- SharePoint Server 2016 error Microsoft Office Online Server 2016 cant be installed on the same machine as a Microsoft SharePoint Server product
- JSON column formatting to preview SharePoint Online file on mouse hover
- How to show Videos on SharePoint Page
- How to get SharePoint Online user details from person or group column using REST API
- How to retrieve all SharePoint Online List Items using Rest API
- How to wrap column text in SharePoint Online Modern List Grid View using JSON formatting
- Recommended size and resolution for SharePoint Online Site logo
- SharePoint List redirect user after submitting form NewForm.aspx
- Add Custom External Link to SharePoint Site Navigation
- Drag drop files here option missing for SharePoint document library
- Can Microsoft SharePoint Lists be synced and accessed offline without internet?
- SharePoint - Use Today's Date Time in list view filter and calculated column
- Convert String to int in Java - Java
- Zodiac Sign & Cusp Calculator - Tools
- How to delete AWS SNS Subscription using CLI - AWS
- How to Check if a Date is Empty (null) or not in Java - Java
- How to check RAM details on Mac? - MacOS
- Clearing the Cache in Firefox Web Browser - HowTos
- Ubuntu Linux: How to Login as root User - Ubuntu
- How to start Microsoft Teams on Mac Startup - Teams