EnjoySharePoint YouTube Channel

Get SharePoint 2013 List Item Count using Rest API and ECMAScript object model

In this post we will discuss how we can get list item count using SharePoint 2013 Rest API as well as using ECMAScript object model. I have a SharePoint 2013 list and I have added a web part page and in that web part page on a button click I am trying to retrieve list item count by using Rest API.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

Related Posts:
SharePoint 2013 Get current user group collection through Rest api

Add Bulk Users to SharePoint 2013 Group from Excel using SharePoint 2013 REST API

Remove User by LoginName from SharePoint 2013 Group using Rest API and Remove User by Id from SharePoint group using Rest API

Get List Item Count using Rest API:
Put the below code in a script editor web part.

<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>
var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘MyTestList’)/items”;
url: requestUri,
type: “GET”,
headers: {
“content-type”: “application/json;odata=verbose”,
success: onSuccess,
error: onError

function onSuccess(data) {
var itemsCount = data.d.results.length;
alert (itemsCount);

function onError(error) {






<input type=”button” id=”btnClick” value=”Count List Items”/>

Get List Item Count using ECMAScript client object model:
We can also retrieve list item count using ECMAScript client object model. Put the below code inside a script editor web part.

<script type=”text/javascript”>
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, “sp.js”);
function Initialize()
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle(“MyTestList”);
var camlQuery = new SP.CamlQuery();
var q = “<View><Query><Where><Eq><FieldRef Name=’Title’ /><Value Type=’Text’>abc</Value></Eq></Where></Query><RowLimit>0</RowLimit></View>”;
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, ‘Include(Title)’);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
function onListItemsLoadSuccess(sender, args) {

var count = this.listItems.get_count();


function onQueryFailed(sender, args) {
alert(‘request failed ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());

Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →