Taking Advantage of the SharePoint 2013 REST API
-
Upload
eric-shupps -
Category
Technology
-
view
13.691 -
download
7
Transcript of Taking Advantage of the SharePoint 2013 REST API
![Page 1: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/1.jpg)
Get Some REST: SharePoint 2013 REST API's
Eric Shupps
SharePoint Server MVP
![Page 2: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/2.jpg)
Sponsored by:
Visit us on the web at www.binarywave.com
Real-time application monitoring, event management, and operational health metrics for Microsoft SharePoint
Reduce troubleshooting time by up to 30%Increase efficiency and improve user satisfactionAvoid downtime and costly outagesMeet or exceed service level agreementsMaximize investment in current infrastructure
![Page 3: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/3.jpg)
About Me
CKS:DEV
The
SharePoint
Cowboy
Patterns
&
Practices
Eric Shupps
www.sharepointcowboy.com [email protected] facebook.com/sharepointcowboy @eshupps
![Page 4: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/4.jpg)
Agenda
Introduction
Basic
Operations
JavaScript
Endpoints
Advanced
Methods
Windows 8
![Page 5: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/5.jpg)
INTRODUCTION
![Page 6: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/6.jpg)
Background
HTTP-based web service architecture that
uses nouns and verbs to define operations
Noun: “Items”
Verbs: GET, POST, PUT, DELETE
OData provides metadata, object typing
and query semantics for underlying data
structure (WCF data services)
/items(0)
Client Object Model service (client.svc)
processes queries, interacts with server OM,
returns formatted response (JSON, XML)
/items/GetByTitle(‘foo’)
![Page 7: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/7.jpg)
Implementation
Clien
t.sv
c
Server
OM
Content
DBREAD
CREATE
UPDATE
DELETE
POST
GET
PUT, MERGE, DELETE
![Page 8: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/8.jpg)
Structure
http://contoso/_api/items/GetById(1)?$select=Title,ID
Location Service Resource Path Query Options
![Page 9: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/9.jpg)
Security
Local
Current
Context
Request
Digest
Remote
OAuth
Access
Token
Cross
Domain
Request
Executor
SP.WebProxy
HTTP
WebRequest
Context
Info
Cross
Domain
![Page 10: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/10.jpg)
Gotchas
OData Spec != SharePoint REST
No request batching
Must specify “odata=verbose” in header
Default response format is ATOM
Use CSOM notation when accessing
static methods and properties
Some requests may not return default
values due to processing overhead
![Page 11: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/11.jpg)
ENDPOINTS
![Page 12: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/12.jpg)
SharePoint 2013 REST Endpoints
Site Web PublishingUser
Profiles
Webs
Features
Event
Receivers
Users
Profiles
Activity
Lists
Items
Pages
Variations
Navigation
Query Results
Suggestions
Search Taxonomy
Managed
Metadata
![Page 13: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/13.jpg)
Metadata
You
Must
Be
Joking!
![Page 14: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/14.jpg)
BASIC OPERATIONS
![Page 15: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/15.jpg)
Sites
http://<site collection>/<site>/_api/sites/features/GetById(guid’<value>’)
http://<site collection>/<site>/_api/sites/eventreceivers
View Event Receivers
http://<site collection>/<site>/_api/web/webinfos/add
{ 'd' :{'parameters': {
'__metadata': {'type': 'SP.WebInfoCreationInformation' }, 'Url': 'RestSubWeb', 'Title': 'RestSubWeb', 'Description': 'rest created web','Language':1033,'WebTemplate':'sts','UseUniquePermissions':false}
}}
Create a Site
Get Feature
![Page 16: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/16.jpg)
Lists
http://<site collection>/<site>/_api/lists
Get All Lists
http://<site collection>/<site>/_api/lists/GetByTitle(‘Shared Documents’)
Get List
http://<site collection>/<site>/_api/lists/GetByTitle(‘Shared Documents’)/items/GetById(0)
Get List Item
http://<site collection>/<site>/_api/lists/GetByTitle(‘Shared Documents’)/items/GetById(1)?$select=Title,ID
Get List Item with Specific Properties
![Page 17: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/17.jpg)
Search
http://<site collection>/<site>/_api/search/query?queryText=‘Value’
Simple Term
http://<site collection>/<site>/_api/search/query?queryText=‘PreferredName:Robert Smith’
Item Property
http://<site collection>/<site>/_api/search/suggest?queryText=‘quarterly sales’
Suggestions
![Page 18: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/18.jpg)
Social
http://<site collection>/<site>/_api/social.following/followed
Get Followed Users
http://<siteCollection>/<site>/_api/social.following/my/followeddocumentsuri
Get Followed Documents
http://<site collection>/<site>/_api/sp.userprofiles.peoplemanager/getmysuggestions
Get Suggestions
http://<siteCollection>/<site>/_api/sp.userprofiles.peoplemanager/getpeoplefollowedby(accountName=@v)?@v='domain\user'
Get Followers
![Page 19: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/19.jpg)
ADVANCED METHODS
![Page 20: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/20.jpg)
Queries
http://<site>/_api/Web/Lists(guid’<value>′)/Items(1)/FieldValuesAsHtml
HTML Values
http://<site>/_api/web/lists/getbytitle(‘Products’)/items()/?$select=Title,Price,effectivebasepermissions
Get Permissions
http://<site>/_api/web/lists/getbytitle('Products')/items()?$select=Title,Price,Supplier_/Title&$expand=Supplier_/Title
Join
![Page 21: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/21.jpg)
Sorting & Filtering
http://<site>/_api/web/lists/getbytitle(‘Products’)/items/?$filter=Price gt 30000
Filter with Comparison
http://<site>/_api/web/lists/getbytitle(‘Products’)/items()?$select=Title,Price,Supplier_/Title&$expand=Supplier_/Title&$filter=Supplier_/Title eq ‘Acme’
Join with Filter
http://<site collection>/<site>/_api/web/lists('<guid>')/items$top=10
Top ‘N’ Results
![Page 22: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/22.jpg)
CRUD Operations
url: http://site url/_api/web/lists/GetByTitle(‘Test')/itemsmethod: POSTbody: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'Test'}headers:Authorization = "Bearer " + accessTokenX-RequestDigest = form digest valueaccept: "application/json;odata=verbose"content-type: "application/json;odata=verbose"content-length:1024
Create a List Item
url: http://site url/_api/web/lists/GetByTitle(‘Test')/items(item id)method: POSTbody: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'TestUpdated'}headers:Authorization = "Bearer " + accessTokenX-RequestDigest = form digest value“IF-MATCH”: etag or “*”“X-HTTP-Method”:”MERGE”,accept: "application/json;odata=verbose"content-type: "application/json;odata=verbose"content-length:1024
Edit a List Item
![Page 23: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/23.jpg)
Form Digest
Used to prevent replay attacks
Updates will fail without digest value
Local
$("#__REQUESTDIGEST").val()
Remote
POST to /_api/contextinfo
![Page 24: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/24.jpg)
JAVASCRIPT
![Page 25: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/25.jpg)
Operations
Async GET/POST operations using AJAX
library
Cross-Domain Library
SP.RequestExecutor
Remote Apps: SP.AppContextSite with
@target
JSON response
accept: "application/json;odata=verbose"
![Page 26: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/26.jpg)
Authorization
Remote
Use CSOM to set context
Sites/Webs/Lists
– Handled by appweb not hostweb
Pass token in request
– RequestExecutor
Local
Use current context
![Page 27: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/27.jpg)
PROVIDER HOSTED APP
Retrieving SharePoint list data with jQuery, REST and AJAX
![Page 28: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/28.jpg)
WINDOWS 8
![Page 29: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/29.jpg)
Operations
XAML
List items with specific fields
Async
– HTTPClient, HTTPClientHandler
ATOM
LINQ
![Page 30: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/30.jpg)
Authorization
Domain Credentials
Permissions
Enterprise Authentication
Private Networks
![Page 31: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/31.jpg)
WINDOWS 8 APP
Uploading Documents to SharePoint using REST
![Page 32: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/32.jpg)
Sponsored by:
Visit us on the web at www.binarywave.com
Real-time application monitoring, event management, and operational health metrics for Microsoft SharePoint
Reduce troubleshooting time by up to 30%Increase efficiency and improve user satisfactionAvoid downtime and costly outagesMeet or exceed service level agreementsMaximize investment in current infrastructure
![Page 33: Taking Advantage of the SharePoint 2013 REST API](https://reader033.fdocuments.net/reader033/viewer/2022052410/554f84cab4c9052a518b4e35/html5/thumbnails/33.jpg)
Resources
Description Link
Programming Using the SharePoint 2013 REST Service http://bit.ly/TUwC9N
OData URI Conventions http://bit.ly/Ytgdz4
Using the SharePoint 2013 REST Service http://bit.ly/YPHif5
SharePoint 2013 Search REST API http://bit.ly/ZqzOuM
Configuring SharePoint 2013 Search REST for Anonymous Users http://bit.ly/152vFoy
SharePoint 2013 REST TypeScript Library http://sprestts.codeplex.com