SlideShare a Scribd company logo
1
Slide
1
Introduction to WebHooks in
Microsoft SharePoint
Tiago Costa
2
Slide
2
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Tiago Costa
• MVP – Office Server and Services
• MCT and MCT Regional Lead
• IT Consultant, Trainer, Author and Speaker
• Independent Contractor
• Delivering Services Worldwide – Mainly in EU
• tiago.costa@outlook.com | www.tiagocosta.eu
• Follow me @tiagocostapt
3
Slide
3
Follow us:
#O365ENGAGE17
People say Portugal is a breathtaking country...
4
Slide
4
Follow us:
#O365ENGAGE17
Who would want to lie on beaches like this one?
5
Slide
5
Follow us:
#O365ENGAGE17
Who would want to lie on beaches like this one?
6
Slide
6
Follow us:
#O365ENGAGE17
Wine is terrible...
7
Slide
7
Follow us:
#O365ENGAGE17
Lisbon lives in the past…
8
Slide
8
Follow us:
#O365ENGAGE17
The architecture in the country is so boring.
9
Slide
9
Follow us:
#O365ENGAGE17
No class at all…
10
Slide
10
Follow us:
#O365ENGAGE17
No tasty sweets for dessert. Why God, why?
11
Slide
11
Follow us:
#O365ENGAGE17
Just stay home...
12
Slide
12
Follow us:
#O365ENGAGE17
And never come to Portugal!
13
Slide
13
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Agenda
• Introduction to Microsoft Graph
• Microsoft Graph WebHooks
• Event Handling in SharePoint
• Event Receivers
• Remote Event Receivers
• Conclusions
• Resources
14
Slide
14
Follow us:
#O365ENGAGE17
Event Handling in SharePoint
15
Slide
15
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Why Handle Events?
• Respond to user actions and modifications to content
• Add validation logic for columns on list items
• Cleanup and format content as it is entered by users
• Calculate and store aggregated values
• Initialize a host web with new lists during add-in installation
16
Slide
16
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Event Handling in SharePoint
2003 2007 2010 2013 2016
Server-Side Event Receivers
Remote Event Receivers
SharePoint Webhooks
17
Slide
17
Follow us:
#O365ENGAGE17
Event Receivers
18
Slide
18
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Overview
• Server-side event handling
• Implemented using an event receiver class
• Registration requires referencing of the event receiver class
• Event receivers are deployed by SharePoint solution in a .NET
assembly
• Loaded into SharePoint worker process
19
Slide
19
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Synchronous Events (-ing)
• Executed before data is committed to the Content DB
• Opportunity for pre-processing like validations
• Opportunity to cancel the event
• Run in the same process and thread that triggered the event
• Block the execution of the current thread
• UI will be held up
• Avoid complex time-consuming processing logic
20
Slide
20
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Asynchronous Events (-ed)
• Executed after data is committed to the Content DB
• Cannot be cancelled
• Opportunity for post-processing like notifications
• Run on a background thread and do not block the UI
• This behaviour can be changed by updating the synchronization
property of the event receiver to synchronous
21
Slide
21
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Supported Events
Site/Web Events
Site Delete  
Web Delete  
Web Move  
Web Add (2010) 
Web Provision (2010) 


Feature Events
Feature Activate 
Feature Deactivate 
Feature Install 
Feature Uninstall 
Feature Upgrade 
Workflow Events
Workflow Start (2010)  
Workflow Postpone (2010) 
Workflow Complete (2010) 
Entity Instance Events
Entity Instance Add (2013) 
Entity Instance Delete (2013) 
Entity Instance Update (2013) 
Add-In Lifecycle Events
Add-In Install (2013) 
Add-In Upgrade (2013) 
Add-In Uninstall (2013) 
List Events
List Add (2010)  
List Delete (2010)  
Email Reception 
List Schema Events
Field Add  
Field Delete  
Field Update  
List Item Events
Item Add  
Item Delete  
Item Update  
Item Attachment Add  
Item Attachment Delete  
Item Check In  
Item Check Out  
Item Uncheck Out  
Item File Move  
Item File Convert 
Item Version Delete (2013)  
Security Events (2013)
Group Add  
Group Update  
Group Delete  
Group User Add  
Group User Delete  
Role Definition Add  
Role Definition Delete  
Role Definition Update  
Role Assignment Add  
Role Assignment Delete  
Role Assignment Update  
Break Inheritance  
Reset Inheritance  
22
Slide
22
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Registering Event Receivers
• Declaratively for List and Content Type binding
• Using the object model for all bindings
SPWeb new SPSite "http://localhost"
SPEventReceiverDefinition
"Receiver.Class1"
"Receiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken =10b23036c9b36d6d"
SPEventReceiverType
23
Slide
23
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Event Receiver Implementation
• Inherit from one of the base classes
• Override the corresponding event methods
24
Slide
24
Follow us:
#O365ENGAGE17
Remote Event Receivers
25
Slide
25
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Overview
• Event handler code runs in remote web (not SharePoint)
• SharePoint calls web service in remote web to trigger event
• Supported remote events are a subset of server-side events
• Remote “before” events implemented as two-way events
• Remote “after” events implemented as one-way events
26
Slide
26
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Remote “Before” Events
• Modeled as two-way events
• Execution flow goes to remote web and then back to SharePoint
• Client is blocked while event processing occurs in remote web
• Sample execution flow for two-way event
• Client attempts action which triggers an event (e.g. update item)
• SharePoint host calls to web service in remote web
• SharePoint host blocks until call returns from remote web
• SharePoint host commits action and returns to Client
Two Way Event (aka before event)
Client
Remote
Web
SP Host
1 2
34
27
Slide
27
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Remote “After” Events
• Modeled as one-way events
• Execution flow goes to remote web but does not return
• Unlike “before” events, after events do not block client response
• Sample execution flow for one-way event
• Client attempts action which triggers an event (e.g. update item)
• SharePoint host commits action and returns to Client
• SharePoint host executes one-way WCF call on remote web
One Way Event (aka after event)
Client
Remote
Web
SharePoint
Host
1
3
2
28
Slide
28
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Supported Events
Site/Web Events
Site Delete  
Web Delete  
Web Move  
Web Add 
Web Provision 


Feature Events
Feature Activate
Feature Deactivate
Feature Install
Feature Uninstall
Feature Upgrade
Workflow Events
Workflow Start (2010)
Workflow Postpone (2010)
Workflow Complete (2010)
Entity Instance Events
Entity Instance Add  
Entity Instance Delete  
Entity Instance Update  
Add-In Lifecycle Events
Add-In Install 
Add-In Upgrade 
Add-In Uninstall 
List Events
List Add  
List Delete  
Email Reception
List Schema Events
Field Add  
Field Delete  
Field Update  
List Item Events
Item Add  
Item Delete  
Item Update  
Item Attachment Add  
Item Attachment Delete  
Item Check In  
Item Check Out  
Item Uncheck Out  
Item File Move  
Item File Convert 
Item Version Delete  
Security Events
Group Add  
Group Update  
Group Delete  
Group User Add  
Group User Delete  
Role Definition Add  
Role Definition Delete  
Role Definition Update  
Role Assignment Add  
Role Assignment Delete  
Role Assignment Update  
Break Inheritance  
Reset Inheritance  
29
Slide
29
Follow us:
#O365ENGAGE17
Introduction to the Microsoft Graph API
30
Slide
30
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Developer Vision
• Focus on User experience and their data.
• We should bring user data and user experience into our
applications.
• Microsoft Office has over 1.2 billion users worldwide.
• Office 365 numbers are huge with over 100 million monthly
active subscribers.
31
Slide
31
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Office 365 Developer momentum
"The most strategic
developer surface area
for us is Office 365“
- Satya Nadella
32
Slide
32
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Microsoft Graph
https://graph.microsoft.com/
USERS FILES MAIL CALENDARGROUPS
Insights and relationships from Office Graph
TASKS
33
Slide
33
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
What is the Microsoft Graph?
• Before
• Before Microsoft Graph we had different APIs for each of the
Microsoft Office 365 Services: Files, Mail, Contacts, …
• For each endpoint we had a different OAuth token
• Now!!!
• Gateway to Office 365
• Single endpoint that proxies multiple Microsoft Services
• Version endpoints – beta, v1.0
• Simplifies token acquisition and management
• Eliminates the need to traditional discovery
34
Slide
34
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Single authentication flow for Microsoft Office 365
• Sign users in using OpenID Connect.
• Device apps, web sites, SPAs and service apps.
• Pin apps to Microsoft Office 365 launcher (My apps).
35
Slide
35
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Common consent window
• Single auth flow for accessing all O365
services
• Admin and end-user consent
• Secure protocol
• OpenID Connect and OAuth 2.0
• No capturing user credentials
• Fine-grained access scopes
• Long-term access through refresh tokens.
36
Slide
36
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Authentication Option
• Azure AD only
• Separate auth flow supports Azure AD accounts only
• Azure AD and Microsoft Accounts (Consumer)
• Converged auth flow supports Azure AD accounts and Microsoft
accounts (outlook.com, hotmail.com, etc.)
• Many apps want to sign users in from both Microsoft account
and Azure AD
37
Slide
37
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
TASKS
manager
memberOf
FILES
MESSAGES
workingWith
Shared with me
directReports
createdBy
FILES
CONVERSATIONS
createdBy
workingWith
EVENTS
trendingAround
GROUPS
TASKS
NOTES
NOTES
public
modifiedBy
USER
trendingAround
https://graph.microsoft.com/
38
Slide
38
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
API endpoint - https://graph.microsoft.com
Verb Operation Endpoint
GET My profile https://graph.microsoft.com/v1.0/me
GET My photo https://graph.microsoft.com/v1.0/me/photo/$value
GET My mail https://graph.microsoft.com/v1.0/me/messages
GET
All the items in my drive
(OneDrive)
https://graph.microsoft.com/v1.0/me/drive/root/children
GET My joined teams https://graph.microsoft.com/beta/me/joinedTeams
GET My notebooks https://graph.microsoft.com/v1.0/me/onenote/notebooks
POST Create a section
https://graph.microsoft.com/v1.0/me/onenote/notebooks/{notebo
ok-id}/sections
GET
My organization default
SharePoint Website
https://graph.microsoft.com/v1.0/sites/root
39
Slide
39
Follow us:
#O365ENGAGE17
Microsoft Graph Explorer
Demo
40
Slide
40
Follow us:
#O365ENGAGE17
Microsoft Graph Webhooks
41
Slide
41
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
What’s a Webhook?
• Also called a web callback or HTTP push API
• Way for an app to provide other applications with real-time
information
42
Slide
42
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Microsoft Graph Webhooks
• Using the Microsoft Graph REST API, an app can subscribe to
changes on the following resources:
• Messages
• Events
• Contacts
• Group conversations
• Drive root items
43
Slide
43
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Creating a subscription
• The client sends a subscription (POST) request for a specific
resource.
• Microsoft Graph verifies the request.
• If the request is valid, Microsoft Graph sends a validation token to the
notification URL.
• If the request is invalid, Microsoft Graph sends an error response with
code and details.
• The client sends the validation token back to Microsoft Graph.
44
Slide
44
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Characteristics of subscriptions
• You can create subscriptions for resources such as messages,
events, contacts, and drive root items.
• You can create a subscription to a specific folder
• https://graph.microsoft.com/v1.0/me/mailfolders('inbox')/messages
• Or to a top-level resource
• https://graph.microsoft.com/v1.0/me/messages
• Or on a drive root item
• https://graph.microsoft.com/v1.0/me/drive/root
45
Slide
45
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Renewing a subscription
• The client can renew a subscription with a specific expiration
date of up to three days from the time of request. The
expirationDateTime property is required.
• Subscription renewal example:
46
Slide
46
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Resources
• Microsoft Graph Webhooks Sample for ASP.NET
• https://github.com/OfficeDev/Microsoft-Graph-ASPNET-Webhooks
• Microsoft Graph Webhooks Sample for Node.js
• https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks
47
Slide
47
Follow us:
#O365ENGAGE17
SharePoint Webhooks
48
Slide
48
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
What are WebHooks?
• A way to be notified of a done change
• Push model instead of Pull model
• Universal model used by many services (WordPress, GitHub,
MailChimp, ...)
• First made available in OneDrive and Outlook
• Now available in SharePoint Online
49
Slide
49
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscribe to a Webhook
POST /_api/web/lists('list-id')/subscriptions
Application
Content-Type: application/json
{
"resource": "https://contoso.sharepoint.com/_api/web/lists({id})",
"notificationUrl": "https://{your host}/your/webhook/service",
"expirationDateTime": "2017-06-18T16:17:57+00:00"
}
SharePoint
Service
50
Slide
50
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscribe to a Webhook
Application
Your WebHook
notification
service endpoint
POST https://{your host}/your/webhook/service
?validationToken={randomString}
SharePoint
Service
51
Slide
51
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscribe to a Webhook
Application
Your WebHook
notification
service endpoint
Content-Type: text/plain
{randomString}
HTTP/1.1 200 OK
SharePoint
Service
52
Slide
52
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscribe to a Webhook
SharePoint
Service
Application
Your WebHook
notification
service endpoint
Content-Type: application/json
{
"id": "a8e6d5e6-9f7f-497a-b97f-8ffe8f559dc7",
"expirationDateTime": "2017-06-18T16:17:57Z",
"notificationUrl": "https://{your host}/your/webhook/service",
"resource": "{id}"
}
HTTP/1.1 201 Created
Application
53
Slide
53
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscribe to a Webhook SharePoint
Service
Your WebHook
notification
service endpoint
{
"value":[
{
"subscriptionId":"91779246-afe9-4525-b122-6c199ae89211",
"clientState":"00000000-0000-0000-0000-000000000000",
"expirationDateTime":"2017-06-18T17:27:00.0000000Z",
"resource":"b9f6f714-9df8-470b-b22e-653855e1c181",
"tenantId":"00000000-0000-0000-0000-000000000000",
"siteUrl":"/",
"webId":"dbc5a806-e4d4-46e5-951c-6344d70b62fa"
}
]
}
POST https://{your host}/your/webhook/service
54
Slide
54
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Event Notification SharePoint
Service
Your WebHook
notification
service endpoint
HTTP/1.1 200 OK
55
Slide
55
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Event Processing SharePoint
Service
YourWebHook
notification
service endpoint
HTTP/1.1 200 OK
POST https://{your host}/your/webhook/service
Storage Queue
WebJob
56
Slide
56
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
GetChanges Pattern SharePoint
Service
Your WebHook
notification
service endpoint
Application
Storage Queue WebJob
SQL Azure DB
POST https://{your host}/your/webhook/service
POST /_api/web/lists('list-id')/subscriptions
Grab “CurrentChangeToken” from list
Persist token per
subscription
Persist last used token per subscription
Grab change token from DB
57
Slide
57
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Supported Events
Site/Web Events
Site Delete
Web Delete
Web Move
Web Add
Web Provision


Feature Events
Feature Activate
Feature Deactivate
Feature Install
Feature Uninstall
Feature Upgrade
Workflow Events
Workflow Start (2010)
Workflow Postpone (2010)
Workflow Complete (2010)
Entity Instance Events
Entity Instance Add
Entity Instance Delete
Entity Instance Update
Add-In Lifecycle Events
Add-In Install
Add-In Upgrade
Add-In Uninstall
List Events
List Add
List Delete
Email Reception
List Schema Events
Field Add
Field Delete
Field Update
List Item Events
Item Add 
Item Delete 
Item Update 
Item Attachment Add 
Item Attachment Delete 
Item Check In 
Item Check Out 
Item Uncheck Out 
Item File Move 
Item File Convert 
Item Version Delete 
Security Events
Group Add
Group Update
Group Delete
Group User Add
Group User Delete
Role Definition Add
Role Definition Delete
Role Definition Update
Role Assignment Add
Role Assignment Delete
Role Assignment Update
Break Inheritance
Reset Inheritance
58
Slide
58
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
WebHook Advantages
• WebHooks have a retry mechanism with an incremental back off
strategy (5 times with 5 minute interval)
• WebHook calls are less taxing for your service endpoint
• The WebHook payload is very small
• Notifications are batched because processing depends on the CSOM
GetChanges() call
• WebHooks are more secure as no event information is passed along
during the notification
• WebHooks are easier to consume by “non-SharePoint” developers
• No WCF based endpoints, regular HTTP services are sufficient (e.g.
Web API)
59
Slide
59
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Subscription Renewal
• WebHooks have an expiration date of maximum 6 months after
creation
• You can “renew” a WebHook via a REST call
• PATCH /_api/web/lists('list-id')/subscriptions('subscriptionID')
• Two patterns are possible:
• Have a background job that regularly renews the needed subscriptions
(recommended model)
• Renew at notification time (will drop WebHook if there’s no event within
the defined expiration window)
60
Slide
60
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Debugging
• Connect remote debugger to your service and web job running
in Azure
• Use ngrok (https://ngrok.com/) as alternative to create a tunnel
to your service running on localhost
61
Slide
61
Follow us:
#O365ENGAGE17
SharePoint List Webhooks
Demo
62
Slide
62
Follow us:
#O365ENGAGE17
Conclusions
63
Slide
63
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
SharePoint Version Availability
Event Receivers Remote Event Receivers WebHooks
SharePoint Server 2003 
SharePoint Server 2007 
SharePoint Server 2010 
SharePoint Server 2013  
SharePoint Server 2016  
SharePoint Online  
64
Slide
64
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Supported Event Types
Event Receivers Remote Event Receivers WebHooks
Site/Web events  
List events  
List schema events  
List item events   
Workflow events 
Security events  
Add-in events  
Feature events 
65
Slide
65
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Comparison
Event Receivers Remote Event Receivers WebHooks
Easy to develop   
Event registration   
Event type coverage   
Security   
Robustness   
Compatibility   
Future proof   
Overall   
66
Slide
66
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Conclusions
• Remote Event Receivers are here to stay
• Use Webhooks if:
• Developing exclusively for SharePoint Online (currently)
• Just need to handle list item events (currently)
• Want to leverage automatic retries
• Want to leverage increased security
• Use Remote Event Receivers if:
• Targeting SharePoint On-Prem (2013 or later)
• Need to handle events other than list item events
• Use Server-side Event Receivers if:
• Targeting older versions of SharePoint (before 2013)
67
Slide
67
Follow us:
#O365ENGAGE17
Resources
68
Slide
68
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Resources
• Webhooks in SharePoint
• https://dev.office.com/sharepoint/docs/apis/webhooks
• https://github.com/SharePoint/sp-dev-
samples/tree/master/Samples/WebHooks.List
• Webhooks in Outlook
• https://msdn.microsoft.com/office/office365/APi/notify-rest-operations
• https://github.com/OfficeDev/PnP/tree/dev/Samples/OutlookNotificationsAPI.
WebAPI
• Webhooks in OneDrive
• https://dev.onedrive.com/webhooks/create-subscription.htm
• https://github.com/OneDrive/onedrive-webhooks-aspnet
69
Slide
69
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Getting started
• Get started with SharePoint webhooks
• https://dev.office.com/sharepoint/docs/apis/webhooks/get-started-
webhooks
• Using Azure Functions with SharePoint webhooks
• https://dev.office.com/sharepoint/docs/apis/webhooks/sharepoint-
webhooks-using-azure-functions
70
Slide
70
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Developer Program
http://dev.office.com/devprogram
71
Slide
71
WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June
Follow us:
#O365ENGAGE17
Questions? | Thank You
Tiago Costa
tiago.costa@outlook.com
We’d like to know what you think!
Please fill out the evaluation form you
received at the registration desk for this
session
Session recordings and materials:
Materials will be available on
Office365Engage.com soon

More Related Content

PDF
O365Engage17 - Working With OneDrive for Business
PDF
O365Engage17 - SharePoint Migration Tips from a Superhero
PPTX
O365Engage17 - Getting Away from Google, Best Practises for Migrating to Offi...
PDF
O365Engage17 - Troubleshooting Exchange Active Sync Devices
PDF
O365Engage17 - Managing share point online end to-end with powershell
PDF
O365Engage17 - The Latest and Greatest on Hybrid Exchange
PDF
O365Engage17 - Supercharge Your Applications with the Microsoft Graph API
PDF
O365Engage17 - Microsoft certifications from zero to certified!
O365Engage17 - Working With OneDrive for Business
O365Engage17 - SharePoint Migration Tips from a Superhero
O365Engage17 - Getting Away from Google, Best Practises for Migrating to Offi...
O365Engage17 - Troubleshooting Exchange Active Sync Devices
O365Engage17 - Managing share point online end to-end with powershell
O365Engage17 - The Latest and Greatest on Hybrid Exchange
O365Engage17 - Supercharge Your Applications with the Microsoft Graph API
O365Engage17 - Microsoft certifications from zero to certified!

What's hot (20)

PDF
O365Engage17 - Exchange hybrid in a complex environment
PDF
O365Engage17 - Automating office 365 external sharing
PDF
O365Engage17 - Smart Email Migration Knowing What’s Lurking in the ‘Dark Corn...
PDF
O365Engage17 - What You Need to Know About Migrating to Exchange Online in 2017
PDF
O365Engage17 - Connecting to one drive and onedrive for business
PDF
O365Engage17 - Ins and outs of monitoring office 365
PDF
O365Engage17 - Modern collaboration in teams and projects powered by office 365
PDF
O365Engage17 - Real World Power Apps and Flow
PDF
O365Engage17 - Modern authentication for the office 365 administrator
PDF
O365Engage17 - The Intranet is Dead Long Live the Modern Workplace
PDF
O365Engage17 - Transition your Company to Modern Collaboration
PDF
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
PDF
O365Engage17 - After the migration – managing your office 365 deployment
PDF
O365Engage17 - One drive for business deploy, manage, migrate
PDF
O365Engage17 - Welcome to Office 365 Engage
PDF
O365Engage17 - Mastering power shell with office 365
PDF
O365Engage17 - How to use google analytics with power bi
PDF
O365Engage17 - Microsoft flow speed date
PDF
O365Engage17 - Azure 101 terminology
PDF
O365Engage17 - How to run a search project in sp online
O365Engage17 - Exchange hybrid in a complex environment
O365Engage17 - Automating office 365 external sharing
O365Engage17 - Smart Email Migration Knowing What’s Lurking in the ‘Dark Corn...
O365Engage17 - What You Need to Know About Migrating to Exchange Online in 2017
O365Engage17 - Connecting to one drive and onedrive for business
O365Engage17 - Ins and outs of monitoring office 365
O365Engage17 - Modern collaboration in teams and projects powered by office 365
O365Engage17 - Real World Power Apps and Flow
O365Engage17 - Modern authentication for the office 365 administrator
O365Engage17 - The Intranet is Dead Long Live the Modern Workplace
O365Engage17 - Transition your Company to Modern Collaboration
O365Engage17 - How to Automate SharePoint Provisioning with PNP Framework
O365Engage17 - After the migration – managing your office 365 deployment
O365Engage17 - One drive for business deploy, manage, migrate
O365Engage17 - Welcome to Office 365 Engage
O365Engage17 - Mastering power shell with office 365
O365Engage17 - How to use google analytics with power bi
O365Engage17 - Microsoft flow speed date
O365Engage17 - Azure 101 terminology
O365Engage17 - How to run a search project in sp online
Ad

Similar to O365Engage17 - WebHooks in Microsoft Sharepoint, Do It Like a Ninja! (20)

PPTX
From Event Receivers to SharePoint Webhooks
PPTX
From Event Receivers to SharePoint Webhooks
PPTX
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
PPTX
SPTechCon Austin 2019 - From SharePoint to Office 365 development
PPTX
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
PPTX
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
PPTX
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
PPTX
#ESPC18 how to migrate to the #SharePoint Framework?
PPTX
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
PPTX
#SPSToronto 2018 migrate you custom development to the SharePoint Framework
PPTX
#SPSOttawa 2017 migrate to the #SharePoint Framework #spfx
PDF
O365Engage17 - Building portals with microsoft graph api
PDF
SharePoint Fest DC 2016_Advanced Office365 SharePoint Online Workflows
PPTX
#SPSNYC 2018 Migrate your custom components to the #SharePoint Framework #SPFX
PPTX
The Future of SharePoint - What You Need to Know
PPTX
SharePoint Saturday Calgary 2017 - From SharePoint to Office 365 Development
PPTX
Module 1 - Introduction to the SharePoint Developer Landscape.pptx
PPTX
Create the Modern Workplace with the SharePoint Framework
PPTX
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...
PDF
How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks
From Event Receivers to SharePoint Webhooks (SPS Lisbon 2017)
SPTechCon Austin 2019 - From SharePoint to Office 365 development
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
#ESPC18 how to migrate to the #SharePoint Framework?
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
#SPSToronto 2018 migrate you custom development to the SharePoint Framework
#SPSOttawa 2017 migrate to the #SharePoint Framework #spfx
O365Engage17 - Building portals with microsoft graph api
SharePoint Fest DC 2016_Advanced Office365 SharePoint Online Workflows
#SPSNYC 2018 Migrate your custom components to the #SharePoint Framework #SPFX
The Future of SharePoint - What You Need to Know
SharePoint Saturday Calgary 2017 - From SharePoint to Office 365 Development
Module 1 - Introduction to the SharePoint Developer Landscape.pptx
Create the Modern Workplace with the SharePoint Framework
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...
How to Develop Maintainable Custom Workflows in Office 365 Share Point Online?
Ad

More from NCCOMMS (20)

PDF
O365Con19 - UI:UX 101 Learn How to Design Custom Experiences for SharePoint -...
PDF
O365Con19 - Model-driven Apps or Canvas Apps? - Rick Bakker
PDF
O365Con19 - Office 365 Groups Surviving the Real World - Jasper Oosterveld
PDF
O365Con19 - Developing Timerjob and Eventhandler Equivalents - Adis Jugo
PDF
O365Con19 - Sharepoint with (Artificial) Intelligence - Adis Jugo
PDF
O365Con19 - What Do You Mean 90 days Isn't Enough - Paul Hunt
PDF
O365Con19 - Tips and Tricks for Complex Migrations to SharePoint Online - And...
PDF
O365Con19 - Start Developing Teams Tabs and SharePoint Webparts with SPFX - O...
PDF
O365Con19 - Start Your Journey from Skype for Business to Teams - Sasja Beere...
PDF
O365Con19 - Lets Get Started with Azure Container Instances - Jussi Roine
PDF
O365Con19 - Azure Blackbelt - Jussi Roine
PDF
O365Con19 - Customise the UI in Modern SharePoint Workspaces - Corinna Lins
PDF
O365Con19 - Be The Protagonist of Your Modern Workplace - Corinna Lins
PDF
O365Con19 - How to Really Manage all your Tasks Across Microsoft 365 - Luise ...
PDF
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
PDF
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
PDF
O365Con19 - Keep Control of Your Data with AIP and CA - Bram de Jager
PDF
O365Con19 - Kaizala a Dive Into the Unknown - Rick van Rousselt
PDF
O365Con19 - How to Inspire Users to Unstick from Email - Luise Freese
PDF
O365Con19 - O365 Identity Management and The Golden Config - Chris Goosen
O365Con19 - UI:UX 101 Learn How to Design Custom Experiences for SharePoint -...
O365Con19 - Model-driven Apps or Canvas Apps? - Rick Bakker
O365Con19 - Office 365 Groups Surviving the Real World - Jasper Oosterveld
O365Con19 - Developing Timerjob and Eventhandler Equivalents - Adis Jugo
O365Con19 - Sharepoint with (Artificial) Intelligence - Adis Jugo
O365Con19 - What Do You Mean 90 days Isn't Enough - Paul Hunt
O365Con19 - Tips and Tricks for Complex Migrations to SharePoint Online - And...
O365Con19 - Start Developing Teams Tabs and SharePoint Webparts with SPFX - O...
O365Con19 - Start Your Journey from Skype for Business to Teams - Sasja Beere...
O365Con19 - Lets Get Started with Azure Container Instances - Jussi Roine
O365Con19 - Azure Blackbelt - Jussi Roine
O365Con19 - Customise the UI in Modern SharePoint Workspaces - Corinna Lins
O365Con19 - Be The Protagonist of Your Modern Workplace - Corinna Lins
O365Con19 - How to Really Manage all your Tasks Across Microsoft 365 - Luise ...
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
O365Con19 - Things I've Learned While Building a Product on SharePoint Modern...
O365Con19 - Keep Control of Your Data with AIP and CA - Bram de Jager
O365Con19 - Kaizala a Dive Into the Unknown - Rick van Rousselt
O365Con19 - How to Inspire Users to Unstick from Email - Luise Freese
O365Con19 - O365 Identity Management and The Golden Config - Chris Goosen

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
sap open course for s4hana steps from ECC to s4
Understanding_Digital_Forensics_Presentation.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
Per capita expenditure prediction using model stacking based on satellite ima...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx

O365Engage17 - WebHooks in Microsoft Sharepoint, Do It Like a Ninja!

  • 1. 1 Slide 1 Introduction to WebHooks in Microsoft SharePoint Tiago Costa
  • 2. 2 Slide 2 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Tiago Costa • MVP – Office Server and Services • MCT and MCT Regional Lead • IT Consultant, Trainer, Author and Speaker • Independent Contractor • Delivering Services Worldwide – Mainly in EU • tiago.costa@outlook.com | www.tiagocosta.eu • Follow me @tiagocostapt
  • 3. 3 Slide 3 Follow us: #O365ENGAGE17 People say Portugal is a breathtaking country...
  • 4. 4 Slide 4 Follow us: #O365ENGAGE17 Who would want to lie on beaches like this one?
  • 5. 5 Slide 5 Follow us: #O365ENGAGE17 Who would want to lie on beaches like this one?
  • 10. 10 Slide 10 Follow us: #O365ENGAGE17 No tasty sweets for dessert. Why God, why?
  • 13. 13 Slide 13 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Agenda • Introduction to Microsoft Graph • Microsoft Graph WebHooks • Event Handling in SharePoint • Event Receivers • Remote Event Receivers • Conclusions • Resources
  • 15. 15 Slide 15 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Why Handle Events? • Respond to user actions and modifications to content • Add validation logic for columns on list items • Cleanup and format content as it is entered by users • Calculate and store aggregated values • Initialize a host web with new lists during add-in installation
  • 16. 16 Slide 16 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Event Handling in SharePoint 2003 2007 2010 2013 2016 Server-Side Event Receivers Remote Event Receivers SharePoint Webhooks
  • 18. 18 Slide 18 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Overview • Server-side event handling • Implemented using an event receiver class • Registration requires referencing of the event receiver class • Event receivers are deployed by SharePoint solution in a .NET assembly • Loaded into SharePoint worker process
  • 19. 19 Slide 19 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Synchronous Events (-ing) • Executed before data is committed to the Content DB • Opportunity for pre-processing like validations • Opportunity to cancel the event • Run in the same process and thread that triggered the event • Block the execution of the current thread • UI will be held up • Avoid complex time-consuming processing logic
  • 20. 20 Slide 20 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Asynchronous Events (-ed) • Executed after data is committed to the Content DB • Cannot be cancelled • Opportunity for post-processing like notifications • Run on a background thread and do not block the UI • This behaviour can be changed by updating the synchronization property of the event receiver to synchronous
  • 21. 21 Slide 21 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Supported Events Site/Web Events Site Delete   Web Delete   Web Move   Web Add (2010)  Web Provision (2010)    Feature Events Feature Activate  Feature Deactivate  Feature Install  Feature Uninstall  Feature Upgrade  Workflow Events Workflow Start (2010)   Workflow Postpone (2010)  Workflow Complete (2010)  Entity Instance Events Entity Instance Add (2013)  Entity Instance Delete (2013)  Entity Instance Update (2013)  Add-In Lifecycle Events Add-In Install (2013)  Add-In Upgrade (2013)  Add-In Uninstall (2013)  List Events List Add (2010)   List Delete (2010)   Email Reception  List Schema Events Field Add   Field Delete   Field Update   List Item Events Item Add   Item Delete   Item Update   Item Attachment Add   Item Attachment Delete   Item Check In   Item Check Out   Item Uncheck Out   Item File Move   Item File Convert  Item Version Delete (2013)   Security Events (2013) Group Add   Group Update   Group Delete   Group User Add   Group User Delete   Role Definition Add   Role Definition Delete   Role Definition Update   Role Assignment Add   Role Assignment Delete   Role Assignment Update   Break Inheritance   Reset Inheritance  
  • 22. 22 Slide 22 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Registering Event Receivers • Declaratively for List and Content Type binding • Using the object model for all bindings SPWeb new SPSite "http://localhost" SPEventReceiverDefinition "Receiver.Class1" "Receiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken =10b23036c9b36d6d" SPEventReceiverType
  • 23. 23 Slide 23 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Event Receiver Implementation • Inherit from one of the base classes • Override the corresponding event methods
  • 25. 25 Slide 25 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Overview • Event handler code runs in remote web (not SharePoint) • SharePoint calls web service in remote web to trigger event • Supported remote events are a subset of server-side events • Remote “before” events implemented as two-way events • Remote “after” events implemented as one-way events
  • 26. 26 Slide 26 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Remote “Before” Events • Modeled as two-way events • Execution flow goes to remote web and then back to SharePoint • Client is blocked while event processing occurs in remote web • Sample execution flow for two-way event • Client attempts action which triggers an event (e.g. update item) • SharePoint host calls to web service in remote web • SharePoint host blocks until call returns from remote web • SharePoint host commits action and returns to Client Two Way Event (aka before event) Client Remote Web SP Host 1 2 34
  • 27. 27 Slide 27 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Remote “After” Events • Modeled as one-way events • Execution flow goes to remote web but does not return • Unlike “before” events, after events do not block client response • Sample execution flow for one-way event • Client attempts action which triggers an event (e.g. update item) • SharePoint host commits action and returns to Client • SharePoint host executes one-way WCF call on remote web One Way Event (aka after event) Client Remote Web SharePoint Host 1 3 2
  • 28. 28 Slide 28 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Supported Events Site/Web Events Site Delete   Web Delete   Web Move   Web Add  Web Provision    Feature Events Feature Activate Feature Deactivate Feature Install Feature Uninstall Feature Upgrade Workflow Events Workflow Start (2010) Workflow Postpone (2010) Workflow Complete (2010) Entity Instance Events Entity Instance Add   Entity Instance Delete   Entity Instance Update   Add-In Lifecycle Events Add-In Install  Add-In Upgrade  Add-In Uninstall  List Events List Add   List Delete   Email Reception List Schema Events Field Add   Field Delete   Field Update   List Item Events Item Add   Item Delete   Item Update   Item Attachment Add   Item Attachment Delete   Item Check In   Item Check Out   Item Uncheck Out   Item File Move   Item File Convert  Item Version Delete   Security Events Group Add   Group Update   Group Delete   Group User Add   Group User Delete   Role Definition Add   Role Definition Delete   Role Definition Update   Role Assignment Add   Role Assignment Delete   Role Assignment Update   Break Inheritance   Reset Inheritance  
  • 30. 30 Slide 30 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Developer Vision • Focus on User experience and their data. • We should bring user data and user experience into our applications. • Microsoft Office has over 1.2 billion users worldwide. • Office 365 numbers are huge with over 100 million monthly active subscribers.
  • 31. 31 Slide 31 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Office 365 Developer momentum "The most strategic developer surface area for us is Office 365“ - Satya Nadella
  • 32. 32 Slide 32 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Microsoft Graph https://graph.microsoft.com/ USERS FILES MAIL CALENDARGROUPS Insights and relationships from Office Graph TASKS
  • 33. 33 Slide 33 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 What is the Microsoft Graph? • Before • Before Microsoft Graph we had different APIs for each of the Microsoft Office 365 Services: Files, Mail, Contacts, … • For each endpoint we had a different OAuth token • Now!!! • Gateway to Office 365 • Single endpoint that proxies multiple Microsoft Services • Version endpoints – beta, v1.0 • Simplifies token acquisition and management • Eliminates the need to traditional discovery
  • 34. 34 Slide 34 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Single authentication flow for Microsoft Office 365 • Sign users in using OpenID Connect. • Device apps, web sites, SPAs and service apps. • Pin apps to Microsoft Office 365 launcher (My apps).
  • 35. 35 Slide 35 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Common consent window • Single auth flow for accessing all O365 services • Admin and end-user consent • Secure protocol • OpenID Connect and OAuth 2.0 • No capturing user credentials • Fine-grained access scopes • Long-term access through refresh tokens.
  • 36. 36 Slide 36 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Authentication Option • Azure AD only • Separate auth flow supports Azure AD accounts only • Azure AD and Microsoft Accounts (Consumer) • Converged auth flow supports Azure AD accounts and Microsoft accounts (outlook.com, hotmail.com, etc.) • Many apps want to sign users in from both Microsoft account and Azure AD
  • 37. 37 Slide 37 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 TASKS manager memberOf FILES MESSAGES workingWith Shared with me directReports createdBy FILES CONVERSATIONS createdBy workingWith EVENTS trendingAround GROUPS TASKS NOTES NOTES public modifiedBy USER trendingAround https://graph.microsoft.com/
  • 38. 38 Slide 38 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 API endpoint - https://graph.microsoft.com Verb Operation Endpoint GET My profile https://graph.microsoft.com/v1.0/me GET My photo https://graph.microsoft.com/v1.0/me/photo/$value GET My mail https://graph.microsoft.com/v1.0/me/messages GET All the items in my drive (OneDrive) https://graph.microsoft.com/v1.0/me/drive/root/children GET My joined teams https://graph.microsoft.com/beta/me/joinedTeams GET My notebooks https://graph.microsoft.com/v1.0/me/onenote/notebooks POST Create a section https://graph.microsoft.com/v1.0/me/onenote/notebooks/{notebo ok-id}/sections GET My organization default SharePoint Website https://graph.microsoft.com/v1.0/sites/root
  • 41. 41 Slide 41 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 What’s a Webhook? • Also called a web callback or HTTP push API • Way for an app to provide other applications with real-time information
  • 42. 42 Slide 42 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Microsoft Graph Webhooks • Using the Microsoft Graph REST API, an app can subscribe to changes on the following resources: • Messages • Events • Contacts • Group conversations • Drive root items
  • 43. 43 Slide 43 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Creating a subscription • The client sends a subscription (POST) request for a specific resource. • Microsoft Graph verifies the request. • If the request is valid, Microsoft Graph sends a validation token to the notification URL. • If the request is invalid, Microsoft Graph sends an error response with code and details. • The client sends the validation token back to Microsoft Graph.
  • 44. 44 Slide 44 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Characteristics of subscriptions • You can create subscriptions for resources such as messages, events, contacts, and drive root items. • You can create a subscription to a specific folder • https://graph.microsoft.com/v1.0/me/mailfolders('inbox')/messages • Or to a top-level resource • https://graph.microsoft.com/v1.0/me/messages • Or on a drive root item • https://graph.microsoft.com/v1.0/me/drive/root
  • 45. 45 Slide 45 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Renewing a subscription • The client can renew a subscription with a specific expiration date of up to three days from the time of request. The expirationDateTime property is required. • Subscription renewal example:
  • 46. 46 Slide 46 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Resources • Microsoft Graph Webhooks Sample for ASP.NET • https://github.com/OfficeDev/Microsoft-Graph-ASPNET-Webhooks • Microsoft Graph Webhooks Sample for Node.js • https://github.com/OfficeDev/Microsoft-Graph-Nodejs-Webhooks
  • 48. 48 Slide 48 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 What are WebHooks? • A way to be notified of a done change • Push model instead of Pull model • Universal model used by many services (WordPress, GitHub, MailChimp, ...) • First made available in OneDrive and Outlook • Now available in SharePoint Online
  • 49. 49 Slide 49 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscribe to a Webhook POST /_api/web/lists('list-id')/subscriptions Application Content-Type: application/json { "resource": "https://contoso.sharepoint.com/_api/web/lists({id})", "notificationUrl": "https://{your host}/your/webhook/service", "expirationDateTime": "2017-06-18T16:17:57+00:00" } SharePoint Service
  • 50. 50 Slide 50 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscribe to a Webhook Application Your WebHook notification service endpoint POST https://{your host}/your/webhook/service ?validationToken={randomString} SharePoint Service
  • 51. 51 Slide 51 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscribe to a Webhook Application Your WebHook notification service endpoint Content-Type: text/plain {randomString} HTTP/1.1 200 OK SharePoint Service
  • 52. 52 Slide 52 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscribe to a Webhook SharePoint Service Application Your WebHook notification service endpoint Content-Type: application/json { "id": "a8e6d5e6-9f7f-497a-b97f-8ffe8f559dc7", "expirationDateTime": "2017-06-18T16:17:57Z", "notificationUrl": "https://{your host}/your/webhook/service", "resource": "{id}" } HTTP/1.1 201 Created Application
  • 53. 53 Slide 53 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscribe to a Webhook SharePoint Service Your WebHook notification service endpoint { "value":[ { "subscriptionId":"91779246-afe9-4525-b122-6c199ae89211", "clientState":"00000000-0000-0000-0000-000000000000", "expirationDateTime":"2017-06-18T17:27:00.0000000Z", "resource":"b9f6f714-9df8-470b-b22e-653855e1c181", "tenantId":"00000000-0000-0000-0000-000000000000", "siteUrl":"/", "webId":"dbc5a806-e4d4-46e5-951c-6344d70b62fa" } ] } POST https://{your host}/your/webhook/service
  • 54. 54 Slide 54 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Event Notification SharePoint Service Your WebHook notification service endpoint HTTP/1.1 200 OK
  • 55. 55 Slide 55 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Event Processing SharePoint Service YourWebHook notification service endpoint HTTP/1.1 200 OK POST https://{your host}/your/webhook/service Storage Queue WebJob
  • 56. 56 Slide 56 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 GetChanges Pattern SharePoint Service Your WebHook notification service endpoint Application Storage Queue WebJob SQL Azure DB POST https://{your host}/your/webhook/service POST /_api/web/lists('list-id')/subscriptions Grab “CurrentChangeToken” from list Persist token per subscription Persist last used token per subscription Grab change token from DB
  • 57. 57 Slide 57 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Supported Events Site/Web Events Site Delete Web Delete Web Move Web Add Web Provision   Feature Events Feature Activate Feature Deactivate Feature Install Feature Uninstall Feature Upgrade Workflow Events Workflow Start (2010) Workflow Postpone (2010) Workflow Complete (2010) Entity Instance Events Entity Instance Add Entity Instance Delete Entity Instance Update Add-In Lifecycle Events Add-In Install Add-In Upgrade Add-In Uninstall List Events List Add List Delete Email Reception List Schema Events Field Add Field Delete Field Update List Item Events Item Add  Item Delete  Item Update  Item Attachment Add  Item Attachment Delete  Item Check In  Item Check Out  Item Uncheck Out  Item File Move  Item File Convert  Item Version Delete  Security Events Group Add Group Update Group Delete Group User Add Group User Delete Role Definition Add Role Definition Delete Role Definition Update Role Assignment Add Role Assignment Delete Role Assignment Update Break Inheritance Reset Inheritance
  • 58. 58 Slide 58 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 WebHook Advantages • WebHooks have a retry mechanism with an incremental back off strategy (5 times with 5 minute interval) • WebHook calls are less taxing for your service endpoint • The WebHook payload is very small • Notifications are batched because processing depends on the CSOM GetChanges() call • WebHooks are more secure as no event information is passed along during the notification • WebHooks are easier to consume by “non-SharePoint” developers • No WCF based endpoints, regular HTTP services are sufficient (e.g. Web API)
  • 59. 59 Slide 59 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Subscription Renewal • WebHooks have an expiration date of maximum 6 months after creation • You can “renew” a WebHook via a REST call • PATCH /_api/web/lists('list-id')/subscriptions('subscriptionID') • Two patterns are possible: • Have a background job that regularly renews the needed subscriptions (recommended model) • Renew at notification time (will drop WebHook if there’s no event within the defined expiration window)
  • 60. 60 Slide 60 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Debugging • Connect remote debugger to your service and web job running in Azure • Use ngrok (https://ngrok.com/) as alternative to create a tunnel to your service running on localhost
  • 63. 63 Slide 63 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 SharePoint Version Availability Event Receivers Remote Event Receivers WebHooks SharePoint Server 2003  SharePoint Server 2007  SharePoint Server 2010  SharePoint Server 2013   SharePoint Server 2016   SharePoint Online  
  • 64. 64 Slide 64 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Supported Event Types Event Receivers Remote Event Receivers WebHooks Site/Web events   List events   List schema events   List item events    Workflow events  Security events   Add-in events   Feature events 
  • 65. 65 Slide 65 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Comparison Event Receivers Remote Event Receivers WebHooks Easy to develop    Event registration    Event type coverage    Security    Robustness    Compatibility    Future proof    Overall   
  • 66. 66 Slide 66 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Conclusions • Remote Event Receivers are here to stay • Use Webhooks if: • Developing exclusively for SharePoint Online (currently) • Just need to handle list item events (currently) • Want to leverage automatic retries • Want to leverage increased security • Use Remote Event Receivers if: • Targeting SharePoint On-Prem (2013 or later) • Need to handle events other than list item events • Use Server-side Event Receivers if: • Targeting older versions of SharePoint (before 2013)
  • 68. 68 Slide 68 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Resources • Webhooks in SharePoint • https://dev.office.com/sharepoint/docs/apis/webhooks • https://github.com/SharePoint/sp-dev- samples/tree/master/Samples/WebHooks.List • Webhooks in Outlook • https://msdn.microsoft.com/office/office365/APi/notify-rest-operations • https://github.com/OfficeDev/PnP/tree/dev/Samples/OutlookNotificationsAPI. WebAPI • Webhooks in OneDrive • https://dev.onedrive.com/webhooks/create-subscription.htm • https://github.com/OneDrive/onedrive-webhooks-aspnet
  • 69. 69 Slide 69 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Getting started • Get started with SharePoint webhooks • https://dev.office.com/sharepoint/docs/apis/webhooks/get-started- webhooks • Using Azure Functions with SharePoint webhooks • https://dev.office.com/sharepoint/docs/apis/webhooks/sharepoint- webhooks-using-azure-functions
  • 70. 70 Slide 70 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Developer Program http://dev.office.com/devprogram
  • 71. 71 Slide 71 WebHooks in Microsoft SharePoint - Do It Like a Ninja! | Tiago Costa | 16:15 – 17:30 - Day 3, Thursday 22 June Follow us: #O365ENGAGE17 Questions? | Thank You Tiago Costa tiago.costa@outlook.com We’d like to know what you think! Please fill out the evaluation form you received at the registration desk for this session Session recordings and materials: Materials will be available on Office365Engage.com soon