sptechcon - get some rest - taking advantage of the sharepoint 2013 rest api
TRANSCRIPT
![Page 1: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/1.jpg)
Taking Advantage of the SharePoint 2013 REST API
![Page 2: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/2.jpg)
CKS:DEV
The
SharePoint
Cowboy
Patterns
&
Practices
Eric Shupps
www.sharepointcowboy.com [email protected] facebook.com/sharepointcowboy @eshupps
![Page 3: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/3.jpg)
Introduction
Basic
Operations
JavaScript
Endpoints
Advanced
Methods
Windows 8
![Page 4: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/4.jpg)
INTRODUCTION
![Page 5: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/5.jpg)
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 6: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/6.jpg)
Clien
t.sv
c
Server
OM
Content
DBREAD
CREATE
UPDATE
DELETE
POST
GET
PUT, MERGE, DELETE
![Page 7: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/7.jpg)
http://contoso/_api/items/GetById(1)?$select=Title,ID
Location Service Resource Path Query Options
![Page 8: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/8.jpg)
Local
Current
Context
Request
Digest
Remote
OAuth
Access
Token
Cross
Domain
Request
Executor
SP.WebProxy
HTTP
WebRequest
Context
Info
Cross
Domain
![Page 9: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/9.jpg)
![Page 10: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/10.jpg)
ENDPOINTS
![Page 11: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/11.jpg)
Site Web PublishingUser
Profiles
Webs
Features
Event
Receivers
Users
Profiles
Activity
Lists
Items
Pages
Variations
Navigation
Query Results
Suggestions
Search Taxonomy
Managed
Metadata
![Page 12: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/12.jpg)
BASIC OPERATIONS
![Page 13: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/13.jpg)
• SP.RequestExecutor
• accept: "application/json;odata=verbose"
![Page 14: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/14.jpg)
![Page 15: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/15.jpg)
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: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/16.jpg)
![Page 17: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/17.jpg)
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 18: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/18.jpg)
![Page 19: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/19.jpg)
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 20: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/20.jpg)
![Page 21: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/21.jpg)
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 22: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/22.jpg)
![Page 23: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/23.jpg)
ADVANCED METHODS
![Page 24: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/24.jpg)
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 25: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/25.jpg)
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 26: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/26.jpg)
![Page 27: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/27.jpg)
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 28: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/28.jpg)
• Used to prevent replay attacks
• Updates will fail without digest value
• Local
• $("#__REQUESTDIGEST").val()
• Remote
• POST to /_api/contextinfo
![Page 29: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/29.jpg)
![Page 30: SPTECHCON - Get Some REST - Taking Advantage of the SharePoint 2013 REST API](https://reader031.vdocuments.us/reader031/viewer/2022020207/554f8526b4c905435d8b4b6f/html5/thumbnails/30.jpg)
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