You can perform basic Create, Read, Update, Delete, and Filter (CRUD) operations by using the Representational State Transfer (REST) interface provided by SharePoint.
In this SharePoint tutorial, we will discuss how to insert, update, delete and retrieve list items using Rest API in SharePoint Online/2013/2016. This tutorial is all about SharePoint rest API crud operations.
Here I am explaining all commands related to SharePoint list items which is mostly used in SharePoint REST API.
Basic SharePoint Rest API End point examples
Below are a few rest api endpoints examples which we use in SharePoint Online/2013/2016.
URL | Details | Method Used |
/_api/Web/Lists/ getbytitle(‘yourListName’) | Get data from SharePoint list | GET |
/_api/web/Lists/getByTitle(‘Student’)/items?$filter=’Internal Name of the column’ eq “Some value | Get List Item by Column Value | GET |
/_api/Web/Lists/getbytitle(‘listname’)/Items | Getting data and adding data in a list | GET/POST |
/_api/web/lists/getbytitle(‘listname’) /GetItemById(itemId) | Get, update and delete a single item | GET, PUT, PATCH, MERGE, DELETE |
/_api/web/lists/getbytitle(‘listname’)/Items/ ?$select=Title,FieldName/Id&$expand= FieldName /Id | Retrieve lookup value | GET/POST |
/_api/web/lists/GetByTitle(‘Your List Name’)/items(Your record ID) | Update records | POST/MERGE |
/_api/web/lists/GetByTitle(‘Your List Name’)/items(Your record ID) | Delete Records | POST/DELETE |
$filter=AuthorId eq <UserId> | Get list item created by logged in user | GET |
$filter=StartDate ge datetime'” + today.toISOString() | Filter date based on Start Date | GET |
/_api/lists/getbytitle (‘’listname’)/items?$orderby=Title | Getting data order by column | GET |
/_api/web/lists/getbytitle(‘StoryDate’)/Items?$filter=Created leq ’11/24/2015′ | Filter date using created column | GET |
Retrieve SharePoint list items using Rest API
Now, we will discuss how to retrieve SharePoint list items using the Rest API in SharePoint. Below is the code to get list items from the SharePoint list using Rest API.
function getListItemsfromList(siteURL, listName)
{
$.ajax({
url: restUrl,
type: GET,
headers:
{
"Accept": "application/json;odata=verbose"
},
cache: false,
success: function(data)
{
console.log(data.d.results);
},
error: function(data)
{
alert(JSON.stringify(error));
}
});
}
Add/Insert item to SharePoint list Rest API
Now, we will discuss how to add or insert an item to the SharePoint list using Rest API. Below is the complete code to insert an item to SharePoint list using Rest API.
function addNewItemInList(restUrl, data) {
$.ajax({
url: restUrl,
type: "POST",
data: JSON.stringify(data),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"Content-Type": "application/json;odata=verbose",
"X-HTTP-Method": "POST"
},
success: function (data) {
console.log(data);
},
error: function (error) {
console.log(JSON.stringify(error));
}
});
}
SharePoint update list item using Rest API
Now, we will see how we can update list item using Rest API in SharePoint 2013/2016/Online.
function updateListItemInList()
{
$.ajax({
url: restUrl,
type: "POST",
data: JSON.stringify
({
__metadata:
{
type: "SP.Data.SpListCRUDListItem"
},
Title: ‘Some Value’
}),
headers:
{
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
},
success: function(data)
{
console.log(data);
},
error: function(error)
{
console.log(JSON.stringify(error));
}
});
}
Delete list item using rest api SharePoint 2013
Now, we will see how can we delete list item using Rest API in SharePoint 2013/2016/Online
function deleteListItemInList()
{
$.ajax({
url: restUrl,
type: "POST",
headers:
{
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",
"X-HTTP-Method": "DELETE"
},
success: function(data)
{
console.log(data);
},
error: function(error)
{
console.log(error);
}
});
}
You may like following SharePoint Rest API tutorials:
- Create SharePoint Quote of the day web part using Rest API and Bootstrap
- Display Task List data in a table using SharePoint REST API and filter by status column
- Google Pie Chart in SharePoint Online (Step by Step tutorial)
- Display SharePoint list item level attachments using REST API and JQuery in SharePoint 2013
- Upload multiple attachments to list items using JSOM and REST API in SharePoint online
- How to get documents from document library in SharePoint using Rest API
I hope this SharePoint tutorial helps to know how to add, update, delete and retrieve list items using Rest API in SharePoint Online/2013/2016. Did you enjoy the examples for SharePoint Rest API Crud Operations?
Rajkiran is currently working as a SharePoint Consultant in India . Rajkiran having 7+ years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).
[…] If you are new to Rest API SharePoint, then you can also check SharePoint Rest API Crud Operations. […]
[…] For this particular example, let us use a script editor web part inside a web part page in SharePoint. In that script editor page, you can add the HTML code as well as the rest API code. […]
[…] same Rest API code, we can use change the default value to a list in SharePoint 2013/2016. As a developer, we should […]
[…] is one of the best tools which is used for API testing. In SharePoint, you can use Postman to check Rest API […]
Hi, how we can make those connection by login from flutter
can u plz let me know how to create new and edit form from share point list using REST API. plz give me some solution with Screen shot for better understanding.