Rest Api How to retrieve list items from SharePoint Online

Source: Internet
Author: User

We'll learn how to call Rest Api in SharePoint Online, this is the requirment:

There is a customer list named "Customers", we'll output the title of all items in the list.

Introduce Rest API:

The request examples in this article assume, you ' re using the Cross-domain library (SP. Requestexecutor.js) to make Cross-domain requests, so they useSP. Appcontextsite in the endpoint URI. See how to:access SharePoint-data from apps using the Cross-domain library for more information.

Note:make sure implement the Sp.requestextcutor.js in page.

Implement in detail:

1. Create a custom list

2. New a project in Napa, add a page and implement the JS

' Use strict ', var currentcontext;var hostcontext;var Hostweb;var Hosturl;var appurl; (function () {//This code runs when the DOM is ready and creates a context object which are//needed to use the SharePoint object model$ (document). Ready (function () {Hosturl = decodeURIComponent (Getquerystringparameter ("Sphosturl")); currentcontext = new SP. Clientcontext.get_current (); hostcontext = new SP.        Appcontextsite (CurrentContext, hosturl); hostweb = Hostcontext.get_web (); AppUrl = decodeURIComponent (Getquerystringparameter ("Spappweburl")); GetListItems ();}); function GetListItems () {var executor = new SP. Requestexecutor (AppUrl); Executor.executeasync ({Url:appurl + "/_api/sp. Appcontextsite (@target)/web/lists/getbytitle (' Customers ')/[email protected]= ' "+ Hosturl +" ' ", Method:" POST ", Body: ' {' query ': {' __metadata ': {' type ': ' SP '. Camlquery '}, ' ViewXml ': ' <View><Query><Where></Where></Query></View> '} ', Headers: {"Accept": "Application/json; Odata=verbose ", "Content-type": "Application/json; Odata=verbose "},success:function (data, req, text) {Console.log (Json.parse (data.body)); var result = Json.parse ( data.body). d.results;for (var i = result.length-1; I >= 0; i--) {$ (". Maincontainer"). Append ("<div>" + result[i] . Title + "</div>");}},error:function (data, req, text) {console.log (data);}});}) ();


3. Debug the project, you'll see the result



More:lists and list items REST API reference










Rest Api How to retrieve list items from SharePoint Online

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.