Introduction to the SharePoint 2013 REST API

Preview:

DESCRIPTION

SharePoint 2013 has extended the REST interface to provide easy access to data within your SharePoint farm. The REST interface opens the SharePoint 2013 development platform to standard Web technologies and languages. This presentation will cover the basics of getting started with the REST service and provide beneficial examples of using REST.

Citation preview

Introduction to the SharePoint 2013 REST API

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

3

AGENDA

REST and ODATA OverviewSharePoint 2013 REST APIDemos

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

5

What is OData?

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

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

7

OData URIs

URI has three partsService root URIResource pathQuery string options

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

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

9

DEMO

10

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

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

12

AJAX Calls

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

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

14

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

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

16

Creating list items

17

Delete list items

18

Update List Items

19

Current REST IssuesREST API does have support for

Managed MetadataWorkflows

Lacks batching support *

20

Questions?

21

Recommended