Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at...

21
Introduction to the SharePoint 2013 REST API

Transcript of Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at...

Page 1: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

Introduction to the SharePoint 2013 REST API

Page 2: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

2

About Me

SharePoint Solutions Architect at Sparkhound in Baton Rougehttp://www.sparkhound.com/pages/blogs.aspx@codygrosLeader of the Baton Rouge SharePoint User Group – www.brspug.com

Page 3: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

3

AGENDA

REST and ODATA OverviewSharePoint 2013 REST APIDemos

Page 4: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

4

REST IntroductionREST = REpresentational State TransferA simpler alternative to SOAP based on HTTP request/response pairsClient sends HTTP requests that target specific resources using unique URIs

Page 5: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

5

What is OData?

Odata is a standardized REST API for Data AccessODATA API maps CRUD operations to HTTP verbshttp://www.odata.org

Page 6: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

6

HTTP MethodsGET

Returns an item or array of itemsPOST

Creates a new itemPUT

Updates an item (replaces all fields with default values)

PATCH or MERGEUpdates an item in place (existing values are retained)

DELETEDeletes an item

Page 7: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

7

OData URIs

URI has three partsService root URIResource pathQuery string options

Service Root URI Resource Path to a SharePoint Object Query String Options

Page 8: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

8

OData Query Option Parameters$select

Specifies which columns to retrieve$filter

Selecting what items to retrieve$orderby

Sorting items$expand

Retrieve results that are usually deferred$top

Select how many items to return$skip

Selecting which row to start at

Page 9: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

9

DEMO

Page 10: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

10

Critical ToolsFiddlerCore jQuery libraryBrowser developer toolsAdvanced REST Client (Chrome App)Postman (Chrome App)

Page 11: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

11

Request HeadersAccept

what type of data you want to receiveContent-type

What type of data you are sending in the request body

X-HTTP-MethodWhich operation to perform

X-RequestDigestEncrypted security value required for updates

IF-MATCHPasses Etag value to control optimistic concurrency

Page 12: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

12

AJAX Calls

$.ajax() function is part of the core jQuery libraryURI end pointAccept header: application/json;odata=verbose

Page 13: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

13

Request DigestProvides security mechanism to protect against replay attacksSharePoint pages has element with ID __REQUESTDIGESTPassed in request by using X-RequestDigest header<site url>/_api/contextinfo

Page 14: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

14

Creating / Updating You must include item type metadata for inserts & updatesAll write operations must pass valid request digest value

Page 15: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

15

List Item Type MetadataEach SharePoint list has a unique type for its list items

String based type value must be passed will all inserts and updates

Page 16: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

16

Creating list items

Page 17: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

17

Delete list items

Page 18: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

18

Update List Items

Page 19: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

19

Current REST IssuesREST API does have support for

Managed MetadataWorkflows

Lacks batching support *

Page 20: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

20

Questions?

Page 21: Introduction to the SharePoint 2013 REST API. 2 About Me SharePoint Solutions Architect at Sparkhound in Baton Rouge .

21