Rest Api how to retrieve list items from SharePoint Online

We will learn how to call Rest Api in SharePoint Online, here is the requirment:

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

Introduce Rest Api:

The request examples in this article assume that you’re using the cross-domain library (SP.RequestExecutor.js) to make cross-domain requests, so they use
SP.AppContextSite in the endpoint URI. See How to: Access SharePoint 2013 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 is
	// 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 will see the result

More:Lists and list items REST API reference



时间: 2024-10-25 08:17:52

Rest Api how to retrieve list items from SharePoint Online的相关文章

RESTful API的设计原则

最近一直在做公司的一个API平台的项目,前后大约有半年多了,中间穿插了好多其他的项目一起做的.上周经理要求写文档,我就重新打开项目开始检阅之前的代码,发现好多地方当初设计的并不合理,忽然就想到,一个好的API平台,应该怎么来设计呢?有哪些规范要遵守呢?面对自己的项目,感觉好多地方都要改,但是已经有人在用了,怎么办?全都要改动吗?所以就上网找解决方案,然后就发现一精品贴,现转载过来,以备不时查阅. 原文地址:http://www.cnblogs.com/moonz-wu/p/4211626.htm

好RESTful API的设计原则

说在前面,这篇文章是无意中发现的,因为感觉写的很好,所以翻译了一下.由于英文水平有限,难免有出错的地方,请看官理解一下.翻译和校正文章花了我大约2周的业余时间,如有人愿意转载请注明出处,谢谢^_^ Principles of good RESTful API Design 好RESTful API的设计原则 Good API design is hard! An API represents a contract between you and those who Consume your da

http://elasticsearch-py.readthedocs.io/en/master/api.html

API Documentation All the API calls map the raw REST api as closely as possible, including the distinction between required and optional arguments to the calls. This means that the code makes distinction between positional and keyword arguments; we,

Get skincluster data with maya&rsquo;s python API

The code below demonstrates, via maya's python api, how to retrieve:– mObject from a mesh, and its skincluster– MFnSkinCluster for the skincluster on that mesh– the influences in that skin cluster and their names– the influence weights for every vert

Paypal获取Transaciton历史交易API初步研究(一)——REST or Classic API

背景: 业务需求,需要开发一款小程序每天自动从Paypal上下载前一天的交易记录,并存入SQL SERVER数据库,以便与财务的Invoice进行金额比对. 开发构想: 采用Java为开发语言,Spring MVC框架,CXF Webservice.持久层采用Hibernate,并通过Spring的Schedule Task完成定时任务功能. 与Paypal的接口参考官方的SDK,但首先需要决定采用REST API或是Classic API. 官方SDK:https://developer.pa

Create a Web API in MVC 6

原文: http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6 ASP.NET 5.0的一个目标是合并MVC和Web API frameworkd. 创建空白ASP.NET 5项目 打开Visual Studio 2015. 在File菜单, 选择 New > Project. 在New Project对话框中, 点击Templates > Visual C# > Web, 选择ASP.NET

Windows 商店应用中使用 SharePoint REST API

前面一篇我们介绍了 Office 365 REST API 的官方工具的使用,本篇我们来看一下 SharePoint REST API 本身的描述.结构和使用方法,以及一些使用经验. 首先来看看SharePoint REST API 的概述: REST API 服务是在 SharePoint 2013 中被引入的,官方认为 REST API 服务可以媲美于现有的 SharePoint 客户端对象模型.开发人员可以使用任何支持 REST Web 请求的技术(C#,javascript,java,o

API翻译 --- Content Provider Basics

IN THIS DOCUMENT Overview           综述 Accessing a provider           访问一个提供者 Content URIs                  内容URI Retrieving Data from the Provider                    检索的数据提供者 Requesting read access permission           请求读访问权限 Constructing the query

android中几个很有用的的api

0x0001 public PackageInfo getPackageArchiveInfo (String archiveFilePath, int flags) Since: API Level 1 Retrieve overall information about an application package defined in a package archive file Parameters archiveFilePath   The path to the archive fi