none
How can we retrive all lists from custom list using REST Api?? RRS feed

All replies

  • Hi MonikaVishwajit,

    Here is the snippet to get data from list using REST API.

      

    <script src="http://code.jquery.com/jquery-1.12.4.js"></script>
     <script>
     $( document ).ready(function() {
     $(document).ready(function(){
     retriveListItem();
     });
    function retriveListItem()  
    {  

        $.ajax  
        ({  
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items",  
            type: type,  
            data: data,  
            headers:  
            {  
                "Accept": "application/json;odata=verbose",  
                "Content-Type": "application/json;odata=verbose",  
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
                "IF-MATCH": "*",  
                "X-HTTP-Method": null  
            },  
            cache: false,  
            success: function(data)   
            {  
                $("#ResultDiv").empty();  
                for (var i = 0; i < data.d.results.length; i++)   
                {  
                    var item = data.d.results[i];  
                    $("#ResultDiv").append(item.Company + "\t" + item.Industry + "<br/>");  
                }  
            },  
            error: function(data)  
            {  
                $("#ResultDiv").empty().text(data.responseJSON.error);  
            }  
        });  
    }
    </script>

    MARK AS ANSWER IF IT HELPS!!


    Thanks Shekhar.diary

    Monday, January 9, 2017 9:40 AM
  • Hi,

    Do you want to retrieve all lists items from custom list?

    We can do this by using PnP JS Core library and it has lot of utilities and extensions using the SharePoint REST API endpoints and it is simple to use.

    $pnp.sp.web.lists.getByTitle("CustomList").items.get().then(function(res) {
        for (i = 0; i < res.length; i++) {
            console.log(res[i].Title);
        }
    });

    Please check the below links for how to use PnP JS library,

    https://github.com/SharePoint/PnP-JS-Core/wiki/Getting-Started:-Install-&-Use

    http://www.ktskumar.com/2016/06/introduction-pnp-js-core-library/



    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me

    Monday, January 9, 2017 10:42 AM
  • Hi, 

    We can get all list items of a list using REST API like below:

    <script src="http://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
    getItems(urlForAllItems)
    var urlForAllItems = "/_api/Web/Lists/GetByTitle('SpTutorial')/Items";
    
    
    
    function getItems(url) {
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + url,
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
            },
            success: function (data) {
                console.log(data.d.results);
            },
            error: function (error) {
                alert(JSON.stringify(error));
            }
        });
    }
    </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, January 10, 2017 9:01 AM