August 2023:
I am using 0365 SharePoint and this did NOT work for me:
"/_api/web/lists/getbytitle('<list title>')/ItemCount"
but this did:
"/_api/lists/getbytitle('<list title>')/ItemCount"
Note the removal of web/
This makes a very fast call and doesn't abuse bandwidth by pulling rows (even select=Id) for no reason and bypasses the REST/oData limits.
Here is what I use. If you do not want to use odata=verbose
in the headers you will want to return data.value
vs data.d.ItemCount
.
/**
Gets list item count avoids oData limits
@date 08/21/2023
@param {string} listname Name of the list.
@param {callback} success The success callback
@param {callback} failure The failure callback
*/
getListItemCount(listname, success, failure) {
var url = common.myWebUrl() + "/_api/lists/getbytitle('" + listname + "')/ItemCount";
$.ajax({
url: url,
async: this.useAsync,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
success(data.d.ItemCount);
},
error: function (data) {
failure(data);
}
});
}
hth
Also, I use a common file for my webUrls based on the project. It's always something like the this:
const webUrl = window.myContext["webAbsoluteUrl"]; //window.webPartContext.pageContext.web.absoluteUrl;
return webUrl;