Retrieve all items from SharePoint 2013 list using REST API

This Rest API tutorial explains, how to retrieve all list items from a SharePoint 2013 list. We will also see how we can list item by id using REST API in SharePoint Online/2013.

Retrieve all list items using Rest API in SharePoint Online/2013/2016

Here I am retrieving list items from the default Announcements list using Rest API. The Announcements list has 3 item which we will retrieve using REST API.

Put the below code inside a Script editor web part and save the page.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
$(function(){
$("#btnClick").click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Announcements')/items";
$.ajax({
url: requestUri,
type: "GET",
headers: {
"accept":"application/json; odata=verbose"
},

success: onSuccess,
error: onError
});

function onSuccess(data) {
var items = data.d.results;
for (var i = 0; i < items.length; i++) {
alert(items[i].Id+ " : " + items[i].Title);
}
}
function onError(error) {

alert(JSON.stringify(error));
}
});
});
</script>

<input type="button" id="btnClick" value="Get all List Items"/>

When you will click on the button, it will display all the items like below:

Retrieve list items using Rest API in SharePoint Online
Retrieve list items using Rest API in SharePoint Online

Retrieve list item by id using REST API in SharePoint Online/2013

Now we will see how we can retrieve a particular item from a SharePoint 2013 list using REST API. Here we will use to getitembyid(id) to retrieve the particular item from the list.

In this example, I have a list where I have 3 columns name as Title, FirstName and LastName.

You can write the below code in a Script Editor web part or content editor web part and Save the web part page.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
$(function(){
$("#btnClick").click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('bijayTestList')/getitembyid(1)";
var requestHeaders = { "accept": "application/json;odata=verbose" };
$.ajax({
url: requestUri,
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: onSuccess,
error: onError
});

function onSuccess(data, request) {
var listiteminfo = data.d;
alert('Title: '+listiteminfo.Title + ' First Name:'+listiteminfo.FirstName +' Last Name: '+listiteminfo.LastName);
}

function onError(error) {
alert("error");
}

});
});

</script>
<input type="button" id="btnClick" value="Click Here"/>

When you click on the button, the result will come like below:

Retrieve list item by id using REST API in SharePoint Online/2013
Retrieve list item by id using REST API in SharePoint Online/2013

You may like following SharePoint Rest API tutorials:

Hope this SharePoint tutorial helps to learn how to retrieve all list items using Rest API in SharePoint 2013/Online. We also saw how we can retrieve list item by id using Rest API in SharePoint 2013/2016 or SharePoint Online.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>