SharePoint Get list items from List view- REST API

In the below code snippet, call the getListViewItems method by passing the weburl, list title and the viewname.

function executeJson(url, method, headers, payload) {
    method = method || 'GET';
    headers = headers || {};
    headers["Accept"] = "application/json;odata=verbose";
    if (method == "POST") {
        headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
    }
    var ajaxOptions = {
        url: url,
        type: method,
        contentType: "application/json;odata=verbose",
        headers: headers
    };
    if (typeof payload != 'undefined') {
        ajaxOptions.data = JSON.stringify(payload);
    }
    return $.ajax(ajaxOptions);
}

function getListItemsByCAML(webUrl, listTitle, queryText) {
    var viewXml = '<View><Query>' + queryText + '</Query></View>';
    var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems";
    var queryPayload = {
        'query': {
            '__metadata': {
                'type': 'SP.CamlQuery'
            },
            'ViewXml': viewXml
        }
    };
    return executeJson(url, "POST", null, queryPayload);
}

function getListViewItems(webUrl, listTitle, viewTitle) {
    var url = webUrl + "/_api/web/lists/getByTitle('" + listTitle + "')/Views/getbytitle('" + viewTitle + "')/ViewQuery";
    return executeJson(url).then(
        function(data) {
            var viewQuery = data.d.ViewQuery;
            return getListItemsByCAML(webUrl, listTitle, viewQuery);
        });
}

thank you :)

Comments

  1. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    "Future Trends & Features of Teen Patti Game App Development"

    ReplyDelete
  2. Insightful and well-written! You’ve highlighted the key aspects perfectly, and the flow was smooth throughout. Thanks for sharing such a detailed and engaging post!
    Teen patti game development company

    ReplyDelete
  3. tycoon games is an engaging mobile app that combines Bollywood trivia with exciting challenges. It lets players test their knowledge of Bollywood movies, actors, songs, and more while competing with friends and other players.

    ReplyDelete
  4. Funny Exchange APK seems convenient for users who prefer accessing gaming content through a mobile device. The website explains the available options clearly, making it easier to understand the platform.

    ReplyDelete

Post a Comment

Popular posts from this blog

SharePoint Online (O365) OAuth Authentication | Authorizing REST API calls against SharePoint Online Site | Get Access token from SharePoint Online | Set up OAuth for SharePoint Online Office 365

SharePoint 2013 REST API Reference

Simple Risk Assessment Matrix table with resultant risk calculation

Kendo UI (Core JavaScript) grid Server Paging, Server Sorting and Server Filtering with Dynamic SQL queries

Sharepoint- Using an Image From formatmap32x32.png in a Ribbon Control