Deep Dive into Office 365 APIs for SharePoint Site services

  • View
    4.970

  • Download
    2

  • Category

    Software

Preview:

Citation preview

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

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

OVERVIEWDeep 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

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

MICROSOFT GRAPH

https://graph.microsoft.com/

UsersMail

Contacts

DocumentsTasks

Office Graph

Spreadsheets

Groups

CalendarFiles

Notes

IM

Presentations Sites

Conversations

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)

GET STARTED WITH OFFICE 365 APISDeep 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

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

ADAL• Azure AD Authentication Library (ADAL) supports:

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

PERMISSIONS (CONNECTED SERVICE)

GRANT ACCESS TO OFFICE 365

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

APP LAUNCHER INTEGRATION

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

FILE OPERATIONS WITH SHAREPOINTCLIENTDeep 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

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/

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

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."}}

DOCUMENT LIBRARIES DO NOT EXIST

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

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

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

LIST OPERATIONS WITH RESTDeep 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

GET ACCESS TOKEN

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

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 …

WRAP-UPDeep 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 …

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

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

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

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

Recommended