Introduction to the SharePoint 2013 REST API
By
QuontraSolutions
Email : info@quontrasolutions.com Call us : 404-900-9988 WebSite : www.quontrasolutions.com
AGENDA ◦ REST and ODATA Overview ◦ SharePoint 2013 REST API ◦ Demos
REST Introduction ◦ REST = REpresentational State Transfer ◦ A simpler alternative to SOAP based on HTTP request/response pairs ◦ Client sends HTTP requests that target specific resources using unique URIs
What is OData? ◦ Odata is a standardized REST API for Data Access ◦ ODATA API maps CRUD operations to HTTP verbs ◦ http://www.odata.org
HTTP Methods ◦ GET ◦ Returns an item or array of items
◦ POST ◦ Creates a new item
◦ PUT ◦ Updates an item (replaces all fields with default values)
◦ PATCH or MERGE ◦ Updates an item in place (existing values are retained)
◦ DELETE ◦ Deletes an item
OData URIs ◦ URI has three parts ◦ Service root URI ◦ Resource path ◦ Query string options
Service Root URI
Resource Path to a SharePoint Object
Query String Options
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
DEMO
Critical Tools ◦ Fiddler ◦ Core jQuery library ◦ Browser developer tools ◦ Advanced REST Client (Chrome App) ◦ Postman (Chrome App)
Request Headers ◦ Accept ◦ what type of data you want to receive ◦ Content-type ◦ What type of data you are sending in the request body ◦ X-HTTP-Method ◦ Which operation to perform ◦ X-Request Digest ◦ Encrypted security value required for updates ◦ IF-MATCH ◦ Passes Etag value to control optimistic concurrency
AJAX Calls ◦ $.ajax() function is part of the core jQuery library ◦ URI end point ◦ Accept header: application/json;odata=verbose
Request Digest ◦ Provides security mechanism to protect against replay attacks ◦ SharePoint pages has element with ID __REQUESTDIGEST ◦ Passed in request by using X-RequestDigest header ◦ <site url>/_api/contextinfo
Creating / Updating â&#x2014;Ś You must include item type metadata for inserts & updates â&#x2014;Ś All write operations must pass valid request digest value
List Item Type Metadata â&#x2014;Ś Each SharePoint list has a unique type for its list items
â&#x2014;Ś String based type value must be passed will all inserts and updates
Creating list items
Delete list items
Update List Items
Current REST Issues ◦ REST API does have support for ◦ Managed Metadata ◦ Workflows
◦ Lacks batching support *
Thank You!