36
DEEP DIVE INTO OFFICE 365 APIS FOR SHAREPOINT SITE SERVICES Bram de Jager Technology Consultant | Macaw Workplace Solutions Microsoft Certified Solutions Master: SharePoint @bramdejager | bramdejager.wordpress.com

Deep Dive into Office 365 APIs for SharePoint Site services

Embed Size (px)

Citation preview

Page 1: Deep Dive into Office 365 APIs for SharePoint Site services

DEEP DIVE INTO OFFICE 365 APIS FOR SHAREPOINT SITE SERVICESBram de JagerTechnology Consultant | Macaw Workplace SolutionsMicrosoft Certified Solutions Master: SharePoint@bramdejager | bramdejager.wordpress.com

Page 2: Deep Dive into Office 365 APIs for SharePoint Site services

AGENDA• Overview• Get Started with Office 365 APIs• File Operations with SharePointClient• List Operations with REST• Wrap-up

Page 3: Deep Dive into Office 365 APIs for SharePoint Site services

OVERVIEWDeep Dive into Office 365 APIs for SharePoint Site services

Page 4: Deep Dive into Office 365 APIs for SharePoint Site services

API’S EVERYWHERE!• SharePoint APIs

o .NET SSOMo .NET CSOMo JavaScript JSOMo REST/OData endpoints

• Office 365 APIo Connect to your users' mail, calendars, contacts, and files into your

app• Microsoft Graph (previously known as Office 365 Unified API)

o Single endpoint for connecting to all of the Office 365 services

Page 5: Deep Dive into Office 365 APIs for SharePoint Site services

OFFICE 365 APISharePointSites

Exchange & Outlook.com

Calendar

Contacts

Mail

OneDrive

OneDrive for Business

Active Directory

Users

Groups

OneDrive Personal

Client API

Search

Sites, Lists and Libs

Taxonomy

BCSWorkflow

Page 6: Deep Dive into Office 365 APIs for SharePoint Site services

MICROSOFT GRAPH

https://graph.microsoft.com/

UsersMail

Contacts

DocumentsTasks

Office Graph

Spreadsheets

Groups

CalendarFiles

Notes

IM

Presentations Sites

Conversations

Page 7: Deep Dive into Office 365 APIs for SharePoint Site services

WHY DO I NEED THE OFFICE 365 APIS?• Access Office 365 data outside of the Office 365 context

o But also integrate with the Office 365 and App Launcher• Single set of APIs for (almost) all Office 365 services• Uniform authentication, with support for

o Federation support (AD FS)o Multi-Factor Authentication (MFA)

Page 8: Deep Dive into Office 365 APIs for SharePoint Site services

GET STARTED WITH OFFICE 365 APISDeep Dive into Office 365 APIs for SharePoint Site services

Page 9: Deep Dive into Office 365 APIs for SharePoint Site services

DISCOVERY SERVICE• Returns a collection of endpoints specific to current user• Intended as the starting point for application

o 1. Sign-Ino 2. Get authorizedo 3. Discover endpoints for resourceo 4. Get Tokeno 5. Access resource

• API Libraries simplify necessary code• Capabilities: https://api.office.com/discovery/v1.0/me/allServices

Page 10: Deep Dive into Office 365 APIs for SharePoint Site services

AUTHENTICATION FLOWNative Application Azure AD Authorization

EndpointAzure AD Token

EndpointOffice 365 API

Request authorization code

Return authorization code

Sign-in via browser (pop-up)

Redeem authorization code and acquire access token for Office 365 resource

Return access token and refresh token

Call Office 365 API using the access token

Return Http Response

Page 11: Deep Dive into Office 365 APIs for SharePoint Site services

ADAL• Azure AD Authentication Library (ADAL) supports:

o Token Acquisitiono Token Cache storing access tokens and refresh tokenso Automatic Token Refresho Asynchronous Methods

Page 12: Deep Dive into Office 365 APIs for SharePoint Site services

PERMISSIONS (CONNECTED SERVICE)

Page 13: Deep Dive into Office 365 APIs for SharePoint Site services

GRANT ACCESS TO OFFICE 365

Page 14: Deep Dive into Office 365 APIs for SharePoint Site services

REVOKE CONSENT• Navigate to https://portal.office.com/myapps

Page 15: Deep Dive into Office 365 APIs for SharePoint Site services

APP LAUNCHER INTEGRATION

Page 16: Deep Dive into Office 365 APIs for SharePoint Site services

DEMO• Get started with Office 365 App development

o Register Office 365 App in Visual Studioo Grant access (user consent)o Implement ADAL for .NET

Page 17: Deep Dive into Office 365 APIs for SharePoint Site services

FILE OPERATIONS WITH SHAREPOINTCLIENTDeep Dive into Office 365 APIs for SharePoint Site services

Page 18: Deep Dive into Office 365 APIs for SharePoint Site services

SHAREPOINT SITES SERVICES• Provides access to SharePoint Online REST API• SharePointClient class simplifies programming, but limited functionality• Direct REST API calls more complex, but exposes more functionality

Page 19: Deep Dive into Office 365 APIs for SharePoint Site services

SHAREPOINTCLIENT CLASS• Discovery Service discovers resource• SharePointClient.Files abstracts Files API

https://api.office.com/discovery/v1.0/me/

https://api.office.com/discovery/

https://company.sharepoint.com/

Page 20: Deep Dive into Office 365 APIs for SharePoint Site services

GET FILES COLLECTION• Get folders and files collection and read file metadata• Get files in specific folder• Type property is either “File” or “Folder”

Page 21: Deep Dive into Office 365 APIs for SharePoint Site services

BUT THERE IS A CATCH!• The API searches for two document libraries, named

o (1) Shared Documents o (2) Documents

• If libraries do not exist, then…o {"error":{"code":"-2146232832,

Microsoft.SharePoint.SPException","message":"The file |0 does not exist."}}

Page 22: Deep Dive into Office 365 APIs for SharePoint Site services

DOCUMENT LIBRARIES DO NOT EXIST

Page 23: Deep Dive into Office 365 APIs for SharePoint Site services

DEMO• Implement Get Files collection• Scenario for the supported document libraries used by the Office 365

API for Siteso Site contains 3 document libraries, named: Shared Documents,

Documents, Other Documentso Remove Shared Documents libraryo Remove Documents library

Page 24: Deep Dive into Office 365 APIs for SharePoint Site services

ADD NEW FILE• Use AddAsync() method• Provide a file name and the file stream

Page 25: Deep Dive into Office 365 APIs for SharePoint Site services

DELETING A FILE• Get the file using GetById() method• Delete using DeleteAsync() method

Page 26: Deep Dive into Office 365 APIs for SharePoint Site services

LIST OPERATIONS WITH RESTDeep Dive into Office 365 APIs for SharePoint Site services

Page 27: Deep Dive into Office 365 APIs for SharePoint Site services

READING LIST ITEMS• Office 365 APIs do not support list operations• Access the SharePoint REST API with the Access Token from the Office

365 API

Page 28: Deep Dive into Office 365 APIs for SharePoint Site services

GET ACCESS TOKEN

Page 29: Deep Dive into Office 365 APIs for SharePoint Site services

DEMO• Implement Reading List Items collection• Use Office 365 API to retrieve Access Token

Page 30: Deep Dive into Office 365 APIs for SharePoint Site services

OTHER REST OPERATIONS• List Items

o Adding a list itemo Updating a list itemo Deleting a list item

• Other REST APIso Taxonomyo Search (Office Graph)o BCSo Workflowo …

Page 31: Deep Dive into Office 365 APIs for SharePoint Site services

WRAP-UPDeep Dive into Office 365 APIs for SharePoint Site services

Page 32: Deep Dive into Office 365 APIs for SharePoint Site services

KEY TAKEAWAY• One API for accessing all Office 365 data

o API makes it easier, limited functionality

o Reuse the Access Token for REST calls• Single repeatable pattern for

o Mailo Contacto Calendaro Fileso OneDriveo …

Page 33: Deep Dive into Office 365 APIs for SharePoint Site services

KEY TAKEAWAY• Another approach to providing solutions

o Build a solution which connects to all Office 365 serviceo App Launcher integrationo Use all capabilities provided by ASP.NET web applicationo Integrate these Office 365 services into

o SharePoint Add-inso Office Add-inso Native apps: Windows Universal Apps, iOS, Android

Page 34: Deep Dive into Office 365 APIs for SharePoint Site services

RESOURCES• Office Dev Center, http://dev.office.com • Get started with Office 365 APIs, http://

dev.office.com/getting-started/office365apis • Office 365 API reference, https://

msdn.microsoft.com/en-us/office/office365/api/api-catalog • Files REST API reference,

https://msdn.microsoft.com/office/office365/APi/files-rest-operations • Authorization Code Grant Flow, https://

msdn.microsoft.com/en-us/library/azure/dn645542.aspx • Kirk Evans Fiddler add-in (oAuth inspector),

http://blogs.msdn.com/b/kaevans/archive/2015/03/30/updated-fiddler-oauth-inspector.aspx

Page 35: Deep Dive into Office 365 APIs for SharePoint Site services

SharePoint Client Browser• Audience: Developer and IT Pro• Insights into your Office 365 Tenant

and/or Site Collection• Exposes the SharePoint CSOM• Supports SharePoint Online and

SharePoint Server• Just released new version• Over 29.000 downloads already!• http://spcb.codeplex.com

Page 36: Deep Dive into Office 365 APIs for SharePoint Site services

QUESTIONS?Bram de Jager@bramdejager | bramdejager.wordpress.com