SharePoint Rest API Crud Operations

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.

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 few rest api end point 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 PowerShell script to retrieve list items from 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 SharePoint list using Rest API. Below is the PowerShell script 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 2013/2016/Online 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:

Hope this SharePoint tutorial helps to know how to add, update, delete and retrieve list items using Rest API in SharePoint Online/2013/2016.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Rajkiran Swain

Rajkiran is currently working as a SharePoint Consultant in QATAR . Rajkiran having 6 + 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 […]

  • >